<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="referrer" content="no-referrer-when-downgrade">
    

    <title>监控中心Zabbix进阶  | matrix</title>
    <meta property="og:title" content="监控中心Zabbix进阶  - matrix">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2021-01-16T14:30:24&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2021-01-16T14:30:24&#43;08:00'>
        
    <meta name="Keywords" content="黑客技术，WEB安全，让你听懂每个漏洞成因，明白每个技术原理,博客,项目管理,python,软件架构,公众号,小程序">
    <meta name="description" content="监控中心Zabbix进阶 ">
        
    <meta name="author" content="matrix">
    <meta property="og:url" content="https://gitmatrix.gitee.io/post/Linux-%E8%BF%90%E7%BB%B4%E7%AC%94%E8%AE%B0/Zabbix/%E7%9B%91%E6%8E%A7%E4%B8%AD%E5%BF%83Zabbix%E8%BF%9B%E9%98%B6/">
    <link rel="shortcut icon" href='/favicon.ico'  type="image/x-icon">

    <link rel="stylesheet" href='/css/normalize.css'>
    <link rel="stylesheet" href='/css/style.css'>
    <script type="text/javascript" src="//cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    
    
        <link href="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet">
    
    
    
    
        <link rel="stylesheet" href='/css/douban.css'>
    
        <link rel="stylesheet" href='/css/other.css'>
    
</head>


<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://gitmatrix.gitee.io/">
                        matrix
                    </a>
                
                <p class="description">黑客技术，WEB安全，让你听懂每个漏洞成因，明白每个技术原理</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://gitmatrix.gitee.io/">首页</a>
                    
                    <a  href="https://gitmatrix.gitee.io/archives/" title="归档">归档</a>
                    
                    <a  href="https://gitmatrix.gitee.io/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#一zabbix-基于snmp监控">一、Zabbix 基于SNMP监控</a>
      <ul>
        <li><a href="#1介绍">1、介绍</a></li>
        <li><a href="#2linux-启用-snmp">2、Linux 启用 snmp</a></li>
        <li><a href="#3配置文件的介绍">3、配置文件的介绍</a></li>
        <li><a href="#4配置snmp监控">4、配置SNMP监控</a></li>
        <li><a href="#5设置入站出站packets-的snmp监控">5、设置入站出站packets 的SNMP监控</a></li>
      </ul>
    </li>
    <li><a href="#二">二、</a>
      <ul>
        <li><a href="#1介绍-1">1、介绍</a></li>
        <li><a href="#2配置jvm接口监控">2、配置JVM接口监控</a></li>
      </ul>
    </li>
    <li><a href="#三zabbix-分布式监控">三、Zabbix 分布式监控</a>
      <ul>
        <li><a href="#1介绍-2">1、介绍</a></li>
        <li><a href="#2实现分布式-zabbix-proxy-监控">2、实现分布式 zabbix proxy 监控</a></li>
      </ul>
    </li>
    <li><a href="#四">四、</a>
      <ul>
        <li><a href="#1官方的-share-分享网站">1、官方的 share 分享网站</a></li>
        <li><a href="#2在node1-上使用此模板">2、在node1 上使用此模板</a></li>
      </ul>
    </li>
    <li><a href="#五zabbix-server-监控自己数据库nginx">五、Zabbix-server 监控自己，数据库，nginx</a>
      <ul>
        <li><a href="#1下载安装配置agent">1、下载安装配置agent</a></li>
        <li><a href="#2自动生成-zabbix-server-的主机">2、自动生成 Zabbix server 的主机</a></li>
        <li><a href="#3在主机中添加模板">3、在主机中添加模板</a></li>
        <li><a href="#4启用zabbix-server">4、启用Zabbix server</a></li>
        <li><a href="#5监控到数据">5、监控到数据</a></li>
      </ul>
    </li>
    <li><a href="#六">六、</a>
      <ul>
        <li><a href="#1申请企业微信">1、申请企业微信</a></li>
        <li><a href="#2配置微信企业号">2、配置微信企业号</a></li>
        <li><a href="#3配置zabbix服务器">3、配置zabbix服务器</a></li>
        <li><a href="#4zabbix-web页面配置告警信息">4、zabbix web页面配置告警信息</a></li>
        <li><a href="#5手动触发告警测试微信接收信息">5、手动触发告警，测试微信接收信息</a></li>
        <li><a href="#6微信客户端检测">6、微信客户端检测</a></li>
      </ul>
    </li>
    <li><a href="#七zabbix-调优">七、Zabbix 调优</a>
      <ul>
        <li><a href="#1调优">1、调优</a></li>
        <li><a href="#2zabbix服务器的进程">2、zabbix服务器的进程</a></li>
        <li><a href="#3其它解决方案">3、其它解决方案</a></li>
        <li><a href="#4grafanacollectdinfluxdb">4、grafana+collectd+influxdb</a></li>
      </ul>
    </li>
    <li><a href="#八zabbix监控实战-tomcat监控">八、Zabbix监控实战-Tomcat监控</a>
      <ul>
        <li><a href="#1方法一开发java监控页面">1、方法一：开发java监控页面</a></li>
        <li><a href="#2方法二使用jps命令进行监控">2、方法二：使用jps命令进行监控</a></li>
        <li><a href="#3tomcat-远程监控功能">3、Tomcat 远程监控功能</a></li>
        <li><a href="#4zabbix-监控-tomcat-程序">4、zabbix 监控 tomcat 程序</a></li>
        <li><a href="#5排除-tomcat-故障步骤">5、排除 tomcat 故障步骤</a></li>
      </ul>
    </li>
    <li><a href="#九zabbix-监控-php-fpm">九、zabbix 监控 php-fpm</a>
      <ul>
        <li><a href="#1修改文件php-fpm">1、修改文件php-fpm</a></li>
        <li><a href="#2修改nginx配置文件">2、修改nginx配置文件</a></li>
        <li><a href="#3curl-127001php_status-我们可以看到php-fpm-的状态信息">3、curl 127.0.0.1/php_status 我们可以看到php-fpm 的状态信息</a></li>
        <li><a href="#4编写监控脚本和监控文件">4、编写监控脚本和监控文件</a></li>
        <li><a href="#5重启服务">5、重启服务</a></li>
        <li><a href="#6在web端进行配置">6、在web端进行配置</a></li>
      </ul>
    </li>
    <li><a href="#十zabbix-监控-mysql">十、zabbix 监控 mysql</a>
      <ul>
        <li><a href="#1监控规划">1、监控规划</a></li>
        <li><a href="#2自定义脚本监控扩展agent">2、自定义脚本监控扩展Agent</a></li>
        <li><a href="#3授权mysql登录用户agent端">3、授权mysql登录用户（agent端）</a></li>
        <li><a href="#4agent端配置">4、agent端配置</a></li>
        <li><a href="#5在web端进行配置">5、在web端进行配置</a></li>
        <li><a href="#6zabbix自带mysql监控项">6、zabbix自带mysql监控项</a></li>
      </ul>
    </li>
    <li><a href="#十一-zabbix其他常用自定义监控项">十一、 zabbix其他常用自定义监控项</a>
      <ul>
        <li><a href="#redis相关的自定义项">redis相关的自定义项</a></li>
        <li><a href="#nginx相关的自定义项">nginx相关的自定义项</a></li>
        <li><a href="#tcp相关的自定义项">TCP相关的自定义项</a></li>
        <li><a href="#系统监控常用自带监控项">系统监控常用自带监控项</a></li>
        <li><a href="#系统监控常用自定义监控项">系统监控常用自定义监控项</a></li>
      </ul>
    </li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">监控中心Zabbix进阶 </h1>
        </header>
        <date class="post-meta meta-date">
            2021年1月16日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='/categories/%E8%BF%90%E7%BB%B4'>运维</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="clear" style="display: none">
            <div class="toc-article">
                <div class="toc-title">文章目录</div>
            </div>
        </div>
        
        <div class="post-content">
            <h1 id="监控中心zabbix进阶">监控中心Zabbix进阶</h1>
<h2 id="一zabbix-基于snmp监控">一、Zabbix 基于SNMP监控</h2>
<h3 id="1介绍">1、介绍</h3>
<ul>
<li>
<p>SNMP：<strong>简单</strong>网络管理协议；（非常古老的协议）</p>
</li>
<li>
<p>三种通信方式：读（get, getnext）、写（set）、trap（陷阱）；</p>
</li>
<li>
<p>端口：</p>
</li>
</ul>
<p>　　161/udp</p>
<p>　　162/udp</p>
<ul>
<li>SNMP协议：年代久远</li>
</ul>
<p>　　v1: 1989</p>
<p>　　v2c 1993</p>
<p>　　v3: 1998</p>
<ul>
<li>
<p>监控网络设备：交换机、路由器</p>
</li>
<li>
<p>MIB：Management Information Base 信息管理基础</p>
</li>
<li>
<p>OID：Object ID 对象ID</p>
</li>
</ul>
<h3 id="2linux-启用-snmp">2、Linux 启用 snmp</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum install net-snmp net-snmp-utils</span>
</code></pre></td></tr></table>
</div>
</div><p>配置文件：定义ACL</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/snmp/snmpd.conf</span>
</code></pre></td></tr></table>
</div>
</div><p>启动服务：</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start snmpd  # 被监控端开启的服务</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start snmptrapd    # 监控端开启的服务（如果允许被监控端启动主动监控时启用）</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="3配置文件的介绍">3、配置文件的介绍</h3>
<p>开放数据：4步</p>
<p>
        <a data-fancybox="gallery" href="/assets/1216496-20171226172045276-679726746.png">
            <img class="mx-auto" alt="img" src="/assets/1216496-20171226172045276-679726746.png" />
        </a>
    </p>
<p>1、定义认证符，将社区名称&quot;public&quot;映射为&quot;安全名称&quot;</p>
<p>2、将安全名称映射到一个组名</p>
<p>3、为我们创建一个视图，让我们的团队有权利</p>
<p>**掩码：**我列出一些注释，有很多，可以再网上查询</p>
<p><strong>.1.3.6.1.2.1.</strong></p>
<p>　　 1.1.0：系统描述信息，SysDesc</p>
<p>　　 1.3.0：监控时间， SysUptime</p>
<p>　　 1.5.0：主机名，SysName</p>
<p>　　 1.7.0：主机提供的服务，SysService</p>
<p>.1.3.6.1.2.2.</p>
<p>　　 2.1.0：网络接口数目</p>
<p>　　 2.2.1.2:网络接口的描述信息</p>
<p>　　 2.2.1.3:网络接口类型</p>
<p>　　 ……</p>
<p>
        <a data-fancybox="gallery" href="/assets/1216496-20171226172045604-1497693285.png">
            <img class="mx-auto" alt="img" src="/assets/1216496-20171226172045604-1497693285.png" />
        </a>
    </p>
<p>4、授予对systemview视图的只读访问权</p>
<p>4、测试工具</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># snmpget -v 2c -c public HOST OID</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># snmpwalk -v 2c -c public HOST OID # 通过这个端口查询到的数据，全列出了</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172045948-698976544.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172045948-698976544.png" />
        </a>
    </p>
<h3 id="4配置snmp监控">4、配置SNMP监控</h3>
<h4 id="1下载修改配置文件">1、下载，修改配置文件</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/snmp/snmpd.conf</span>
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.2      <span style="color:#998;font-style:italic"># 网络接口的相关数据</span>
view    systemview    included   .1.3.6.1.4.1.2021   <span style="color:#998;font-style:italic"># 系统资源负载，memory, disk io, cpu load </span>
view    systemview    included   .1.3.6.1.2.1.25
</code></pre></td></tr></table>
</div>
</div><h4 id="2在-agent-上测试">2、在 agent 上测试</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># snmpget -v 2c -c public 192.168.30.2 .1.3.6.1.2.1.1.3.0</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># snmpget -v 2c -c public 192.168.30.2 .1.3.6.1.2.1.1.5.0</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172046245-1946753487.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172046245-1946753487.png" />
        </a>
    </p>
<h4 id="3在监控页面给node2加一个snmp的接口">3、在监控页面，给node2加一个snmp的接口</h4>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172046541-990434657.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172046541-990434657.png" />
        </a>
    </p>
<h4 id="4在-node2-上加一个-template-os-linux-snmpv2-模板">4、在 node2 上加一个 Template OS Linux SNMPv2 模板</h4>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172046854-1430722762.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172046854-1430722762.png" />
        </a>
    </p>
<ul>
<li>模板添加成功，生成一系列东西</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172047151-639977143.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172047151-639977143.png" />
        </a>
    </p>
<ul>
<li>点开一个item 看一下</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172047463-1455547608.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172047463-1455547608.png" />
        </a>
    </p>
<h4 id="5生成一些最新数据的图形-graph了">5、生成一些最新数据的图形 graph了</h4>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172047729-481410869.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172047729-481410869.png" />
        </a>
    </p>
<h3 id="5设置入站出站packets-的snmp监控">5、设置入站出站packets 的SNMP监控</h3>
<h4 id="1监控网络设备交换机路由器的步骤">1、监控网络设备：交换机、路由器的步骤：</h4>
<ul>
<li>
<p>把交换机、路由器的SNMP 把对应的OID的分支启用起来</p>
</li>
<li>
<p>了解这些分支下有哪些OID，他们分别表示什么意义</p>
</li>
<li>
<p>我们要监控的某一数据：如交换机的某一个接口流量、报文，发送、传入传出的报文数有多少个；传入传出的字节数有多少个，把OID取出来，保存</p>
</li>
</ul>
<h4 id="2定义入站出站的item监控项">2、定义入站出站的item监控项</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">interface traffic packets<span style="color:#000;font-weight:bold">(</span>in<span style="color:#000;font-weight:bold">)</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172048182-394941521.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172048182-394941521.png" />
        </a>
    </p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">interface traffic packets<span style="color:#000;font-weight:bold">(</span>out<span style="color:#000;font-weight:bold">)</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172048510-973935048.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172048510-973935048.png" />
        </a>
    </p>
<h2 id="二">二、</h2>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172048698-2048639928.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172048698-2048639928.png" />
        </a>
    </p>
<h3 id="1介绍-1">1、介绍</h3>
<p>Java虚拟机(JVM)具有内置的插件，使您能够使用JMX监视和管理它。您还可以使用JMX监视工具化的应用程序。</p>
<h4 id="1配置设置介绍">1、配置设置介绍</h4>
<h5 id="1zabbix-java-gateway主机设置">1、zabbix-java-gateway主机设置</h5>
<ul>
<li>安装 zabbix-java-gateway程序包，启动服务；</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum -y install zabbix-java-gateway</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="2zabbix-server端设置需要重启服务">2、zabbix-server端设置（需要重启服务）</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#008080">JavaGateway</span><span style="color:#000;font-weight:bold">=</span>172.16.0.70                    <span style="color:#998;font-style:italic">#即 zabbix server IP地址</span>
<span style="color:#008080">JavaGatewayPort</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">10052</span>
<span style="color:#008080">StartJavaPollers</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">5</span>  <span style="color:#998;font-style:italic">#监控项</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="3tomcat主机设置">3、tomcat主机设置</h5>
<ul>
<li>监控tomcat：</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/sysconfig/tomcat</span>
<span style="color:#008080">CATALINA_OPTS</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;-Djava.rmi.server.hostname=TOMCAT_SERVER_IP -Djavax.management.builder.initial= -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false&#34;</span>   <span style="color:#998;font-style:italic">#启用JVM接口，默认没有启用</span>

jmx<span style="color:#000;font-weight:bold">[</span>object_name,attribute_name<span style="color:#000;font-weight:bold">]</span>
object name      <span style="color:#998;font-style:italic"># 它代表MBean的对象名称</span>
attribute name - <span style="color:#998;font-style:italic"># 一个MBean属性名称，可选的复合数据字段名称以点分隔</span>
示例：
jmx<span style="color:#000;font-weight:bold">[</span><span style="color:#d14">&#34;java.lang:type=Memory&#34;</span>,<span style="color:#d14">&#34;HeapMemoryUsage.used&#34;</span>
</code></pre></td></tr></table>
</div>
</div><p>4、 jmx的详细文档：https://docs.oracle.com/javase/1.5.0/docs/guide/management/agent.html</p>
<ul>
<li><strong>注意:</strong>   如果是手动安装的tomcat  需要编辑  catalina.sh  文件 ，重启 tomcat</li>
</ul>
<h3 id="2配置jvm接口监控">2、配置JVM接口监控</h3>
<h4 id="1安装配置-tomcat">1、安装配置 tomcat</h4>
<h5 id="1下载安装tomcat主要是用jvm">1、下载安装tomcat，主要是用JVM</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum -y install java-1.8.0-openjdk-devel tomcat-admin-webapps tomcat-docs-webapp</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="2加catalina_opts-启用jvm接口默认没有启用">2、加CATALINA_OPTS= #启用JVM接口，默认没有启用</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/sysconfig/tomcat</span>
<span style="color:#008080">CATALINA_OPTS</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;-Djava.rmi.server.hostname=192.168.30.2 -Djavax.management.builder.initial= -Dcom.sun.management.jmxremote=true   -Dcom.sun.management.jmxremote.port=12345  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false&#34;</span>
</code></pre></td></tr></table>
</div>
</div><p>3、开启服务</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start tomcat</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="2在-zabbix-server-端安装配置-java-gateway">2、在 zabbix-server 端安装配置 java-gateway</h4>
<h5 id="1安装配置-java-gateway">1、安装配置 java-gateway</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum -y install zabbix-java-gateway</span>
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/zabbix/zabbix_java_gateway.conf   # 安装完后，会生成一个java_gateway 的配置文件</span>
<span style="color:#008080">LISTEN_IP</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;0.0.0.0&#34;</span>                             <span style="color:#998;font-style:italic">#监听服务器地址</span>
<span style="color:#008080">LISTEN_PORT</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">10052</span>                               <span style="color:#998;font-style:italic">#监听zabbix_java进程的端口，默认是10052</span>
<span style="color:#008080">PID_FILE</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;/tmp/zabbix_java.pid&#34;</span>                 <span style="color:#998;font-style:italic">#zabbix_java的pid路径</span>
<span style="color:#008080">START_POLLERS</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">5</span>                                 <span style="color:#998;font-style:italic">#zabbix_java的进程数</span>
<span style="color:#008080">TIMEOUT</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">10</span>                                      <span style="color:#998;font-style:italic">#zabbix_java的超时时间</span>
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start zabbix-java-gateway.service # 可不用修改，直接开启服务 </span>
</code></pre></td></tr></table>
</div>
</div><h5 id="2修改-server-配置开启-java-gateway-的配置">2、修改 server 配置开启 java-gateway 的配置</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/zabbix/zabbix_server.conf</span>
<span style="color:#008080">JavaGateway</span><span style="color:#000;font-weight:bold">=</span>192.168.30.107  
<span style="color:#008080">JavaGatewayPort</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">10052</span>
<span style="color:#008080">StartJavaPollers</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">5</span>    <span style="color:#998;font-style:italic"># 打开5个监控项</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="3--重启zabbix-server-服务">3、  重启zabbix-server 服务</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl restart zabbix-server </span>
</code></pre></td></tr></table>
</div>
</div><h4 id="3在node2-主机上添加jmx接口实验模板">3、在node2 主机上添加JMX接口，实验模板</h4>
<h5 id="1添加jmx接口">1、添加JMX接口</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172049182-664693382.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172049182-664693382.png" />
        </a>
    </p>
<h5 id="2在-node2-上连接-tomcat-jmx-模板">2、在 node2 上连接 tomcat JMX 模板</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172049541-701630088.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172049541-701630088.png" />
        </a>
    </p>
<h5 id="3随便查看一个监控项-item">3、随便查看一个监控项 item</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172050010-1062166097.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172050010-1062166097.png" />
        </a>
    </p>
<h4 id="4自己定义一个堆内存使用的监控项基于jvm接口没必要使用模板就好">4、自己定义一个堆内存使用的监控项，基于JVM接口（没必要，使用模板就好）</h4>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172050479-619246539.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172050479-619246539.png" />
        </a>
    </p>
<h2 id="三zabbix-分布式监控">三、Zabbix 分布式监控</h2>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172050995-2135249770.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172050995-2135249770.png" />
        </a>
    </p>
<h3 id="1介绍-2">1、介绍</h3>
<p>分布式监控概述：proxy and node</p>
<h4 id="1zabbix-的三种架构">1、Zabbix 的三种架构</h4>
<ul>
<li>
<p>Server-agent</p>
</li>
<li>
<p>Server-Node-agent</p>
</li>
<li>
<p>Server-Proxy-agent</p>
</li>
</ul>
<h4 id="2配置介绍">2、配置介绍</h4>
<p>Zabbix Proxy的配置：</p>
<ul>
<li>
<p>server-node-agent</p>
</li>
<li>
<p>server-proxy-agent</p>
</li>
</ul>
<h5 id="1配置proxy主机">1、配置proxy主机</h5>
<h6 id="1安装程序包">1、安装程序包</h6>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">zabbix-proxy-mysql zabbix-get zabbix-agent zabbix-sender
</code></pre></td></tr></table>
</div>
</div><h6 id="2准备数据库">2、准备数据库</h6>
<p>　　创建、授权用户、导入schema.sql；</p>
<h6 id="3修改配置文件">3、修改配置文件</h6>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#008080">Server</span><span style="color:#000;font-weight:bold">=</span> zabbix server  <span style="color:#998;font-style:italic"># 主机地址；</span>
<span style="color:#008080">Hostname</span><span style="color:#000;font-weight:bold">=</span>              <span style="color:#998;font-style:italic"># 当前代理服务器的名称；在server添加proxy时，必须使用此处指定的名称；需要事先确保server能解析此名称；</span>
<span style="color:#008080">DBHost</span><span style="color:#000;font-weight:bold">=</span>
<span style="color:#008080">DBName</span><span style="color:#000;font-weight:bold">=</span>
<span style="color:#008080">DBUser</span><span style="color:#000;font-weight:bold">=</span>
<span style="color:#008080">DBPassword</span><span style="color:#000;font-weight:bold">=</span>
<span style="color:#008080">ConfigFrequency</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">10</span>    <span style="color:#998;font-style:italic"># proxy被动模式下，server多少秒同步配置文件至proxy。该参数仅用于被动模式下的代理。范围是1-3600*24*7</span>
<span style="color:#008080">DataSenderFrequency</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span> <span style="color:#998;font-style:italic">#代理将每N秒将收集的数据发送到服务器。 对于被动模式下的代理，该参数将被忽略。范围是1-3600</span>
</code></pre></td></tr></table>
</div>
</div><h6 id="4在-server-端添加此-porxy">4、在 server 端添加此 Porxy</h6>
<p>​    Administration &ndash;&gt; Proxies</p>
<h6 id="5在server端配置通过此proxy监控的主机">5、在Server端配置通过此Proxy监控的主机；</h6>
<p>注意：zabbix agent 端要允许 zabbix proxy 主机执行数据采集操作：</p>
<h3 id="2实现分布式-zabbix-proxy-监控">2、实现分布式 zabbix proxy 监控</h3>
<h4 id="1实验前准备">1、实验前准备</h4>
<ul>
<li>
<p>ntpdate 172.168.30.1 同步时间</p>
</li>
<li>
<p>关闭防火墙，selinux</p>
</li>
<li>
<p>设置主机名 hostnamectl set-hostname zbproxy.qfedu.com</p>
</li>
<li>
<p>vim /etc/hosts 每个机器都设置hosts，以解析主机名；DNS也行</p>
</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172051276-274670232.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172051276-274670232.png" />
        </a>
    </p>
<h4 id="2环境配置4台主机">2、环境配置（4台主机）</h4>
<table>
<thead>
<tr>
<th>机器名称</th>
<th>IP配置</th>
<th>服务角色</th>
</tr>
</thead>
<tbody>
<tr>
<td>zabbix-server</td>
<td>192.168.30.107</td>
<td>监控</td>
</tr>
<tr>
<td>agent-node1</td>
<td>192.168.30.7</td>
<td>被监控端</td>
</tr>
<tr>
<td>agent-node2</td>
<td>192.168.30.2</td>
<td>被监控端</td>
</tr>
<tr>
<td>node3</td>
<td>192.168.30.3</td>
<td>代理proxy</td>
</tr>
</tbody>
</table>
<p>zabbix-server 直接监控一台主机 node1</p>
<p>zabbix-server 通过代理 node3 监控 node2</p>
<h4 id="3在-node3-上配置-mysql">3、在 node3 上配置 mysql</h4>
<h5 id="1创建配置-mysql">1、创建配置 mysql</h5>
<h6 id="1创建-mariadbrepo">1、创建 mariadb.repo</h6>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/yum.repos.d/mariadb.repo</span>
写入以下内容：
<span style="color:#000;font-weight:bold">[</span>mariadb<span style="color:#000;font-weight:bold">]</span>
<span style="color:#008080">name</span> <span style="color:#000;font-weight:bold">=</span> MariaDB 
<span style="color:#008080">baseurl</span> <span style="color:#000;font-weight:bold">=</span> https://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64 
<span style="color:#008080">gpgkey</span><span style="color:#000;font-weight:bold">=</span>https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB 
<span style="color:#008080">gpgcheck</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span>
</code></pre></td></tr></table>
</div>
</div><h6 id="2yum-安装最新版本-mariadb">2、yum 安装最新版本 mariadb</h6>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum install -y MariaDB-server MariaDB-clien</span>
</code></pre></td></tr></table>
</div>
</div><ul>
<li>修改配置文件</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/my.cnf.d/server.cnf</span>
    <span style="color:#000;font-weight:bold">[</span>mysqld<span style="color:#000;font-weight:bold">]</span>
    <span style="color:#008080">skip_name_resolve</span> <span style="color:#000;font-weight:bold">=</span> ON          <span style="color:#998;font-style:italic"># 跳过主机名解析</span>
    <span style="color:#008080">innodb_file_per_table</span> <span style="color:#000;font-weight:bold">=</span> ON      <span style="color:#998;font-style:italic"># 开启独立表空间</span>
    <span style="color:#008080">innodb_buffer_pool_size</span> <span style="color:#000;font-weight:bold">=</span> 256M  <span style="color:#998;font-style:italic"># 缓存池大小</span>
    <span style="color:#008080">max_connections</span> <span style="color:#000;font-weight:bold">=</span> <span style="color:#099">2000</span>          <span style="color:#998;font-style:italic"># 最大连接数</span>
    log-bin <span style="color:#000;font-weight:bold">=</span> master-log            <span style="color:#998;font-style:italic"># 开启二进制日志</span>
</code></pre></td></tr></table>
</div>
</div><h6 id="3重启我们的数据库服务">3、重启我们的数据库服务</h6>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic">#  systemctl restart mariadb</span>
<span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic">#  mysql_secure_installation  # 初始化mariadb</span>
</code></pre></td></tr></table>
</div>
</div><h6 id="4创建数据库-和-授权用户">4、创建数据库 和 授权用户</h6>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sql" data-lang="sql">MariaDB [(<span style="color:#000;font-weight:bold">none</span>)]<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#000;font-weight:bold">create</span> <span style="color:#000;font-weight:bold">database</span> zbxproxydb <span style="color:#0086b3">character</span> <span style="color:#000;font-weight:bold">set</span> <span style="color:#d14">&#39;utf8&#39;</span>;
MariaDB [(<span style="color:#000;font-weight:bold">none</span>)]<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#000;font-weight:bold">grant</span> <span style="color:#000;font-weight:bold">all</span> <span style="color:#000;font-weight:bold">on</span> zbxproxydb.<span style="color:#000;font-weight:bold">*</span> <span style="color:#000;font-weight:bold">to</span> <span style="color:#d14">&#39;zbxproxyuser&#39;</span><span style="color:#000;font-weight:bold">@</span><span style="color:#d14">&#39;192.168.30.%&#39;</span> identified <span style="color:#000;font-weight:bold">by</span> <span style="color:#d14">&#39;zbxproxypass&#39;</span>;
MariaDB [(<span style="color:#000;font-weight:bold">none</span>)]<span style="color:#000;font-weight:bold">&gt;</span> flush <span style="color:#000;font-weight:bold">privileges</span>;
</code></pre></td></tr></table>
</div>
</div><h4 id="3在node3-上下载zabbix-相关的包主要是代理proxy的包">3、在node3 上下载zabbix 相关的包，主要是代理proxy的包</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum -y install zabbix-proxy-mysql zabbix-get zabbix-agent zabbix-sender</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="1初始化数据库">1、初始化数据库</h5>
<p>zabbix-proxy-mysql 包里带有，导入数据的文件</p>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172052791-1016956277.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172052791-1016956277.png" />
        </a>
    </p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># cp /usr/share/doc/zabbix-proxy-mysql-3.4.4/schema.sql.gz ./ 复制</span>
<span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># gzip -d schema.sql.gz 解包</span>
<span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># mysql -root -p zbxproxydb &lt; schema.sql 导入数据</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="2查看数据已经生成">2、查看数据已经生成</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172053276-1712858671.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172053276-1712858671.png" />
        </a>
    </p>
<h4 id="4配置-proxy-端">4、配置 proxy 端</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/zabbix/zabbix_proxy.conf</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172053682-47495044.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172053682-47495044.png" />
        </a>
    </p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#008080">Server</span><span style="color:#000;font-weight:bold">=</span>192.168.30.107        <span style="color:#998;font-style:italic"># server 的IP</span>
<span style="color:#008080">ServerPort</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">10051</span>             <span style="color:#998;font-style:italic"># server 的端口</span>

<span style="color:#008080">Hostname</span><span style="color:#000;font-weight:bold">=</span>zbxproxy.qfedu.com  <span style="color:#998;font-style:italic"># 主机名</span>
<span style="color:#008080">ListenPort</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">10051</span>             <span style="color:#998;font-style:italic"># proxy自己的监听端口</span>
<span style="color:#008080">EnableRemoteCommands</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span>       <span style="color:#998;font-style:italic"># 允许远程命令</span>
<span style="color:#008080">LogRemoteCommands</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span>          <span style="color:#998;font-style:italic"># 记录远程命令的日志</span>

<span style="color:#998;font-style:italic"># 数据的配置</span>
<span style="color:#008080">DBHost</span><span style="color:#000;font-weight:bold">=</span>192.168.30.3
<span style="color:#008080">DBName</span><span style="color:#000;font-weight:bold">=</span>zbxproxydb  
<span style="color:#008080">DBUser</span><span style="color:#000;font-weight:bold">=</span>zbxproxyuser
<span style="color:#008080">DBPassword</span><span style="color:#000;font-weight:bold">=</span>zbxproxypass

<span style="color:#008080">ConfigFrequency</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">30</span>      <span style="color:#998;font-style:italic"># 多长时间，去服务端拖一次有自己监控的操作配置；为了实验更快的生效，这里设置30秒，默认3600s</span>
<span style="color:#008080">DataSenderFrequency</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span>   <span style="color:#998;font-style:italic"># 每一秒向server 端发一次数据，发送频度</span>
</code></pre></td></tr></table>
</div>
</div><p>2、开启服务</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start zabbix-proxy</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="5配置node2端允许proxy代理监控">5、配置node2端允许proxy代理监控</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/zabbix/zabbix_agentd.conf</span>
<span style="color:#008080">Server</span><span style="color:#000;font-weight:bold">=</span>192.168.30.107,192.168.30.3
<span style="color:#008080">ServerActive</span><span style="color:#000;font-weight:bold">=</span>192.168.30.107,192.168.30.3
<span style="color:#000;font-weight:bold">[</span>root@node3 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl restart zabbix-agent # 启动服务 </span>
</code></pre></td></tr></table>
</div>
</div><h4 id="6把代理加入监控-server-创建配置agent-代理">6、把代理加入监控 server 创建配置agent 代理</h4>
<h5 id="1创建agent-代理">1、创建agent 代理</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172053932-978486530.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172053932-978486530.png" />
        </a>
    </p>
<h5 id="2配置">2、配置</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172054213-335809349.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172054213-335809349.png" />
        </a>
    </p>
<h4 id="7创建node2-主机并采用代理监控">7、创建node2 主机并采用代理监控</h4>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172054682-1009619727.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172054682-1009619727.png" />
        </a>
    </p>
<ul>
<li>设置代理成功</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172055307-1060200173.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172055307-1060200173.png" />
        </a>
    </p>
<h4 id="8创建item监控项">8、创建item监控项</h4>
<h5 id="1随便创一个监控项-cpu-switches">1、随便创一个监控项 CPU Switches</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172055698-1128474710.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172055698-1128474710.png" />
        </a>
    </p>
<h5 id="2进程里设置每秒更改">2、进程里设置每秒更改</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172055932-1067681793.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172055932-1067681793.png" />
        </a>
    </p>
<h5 id="3成功graph-图形生成">3、成功graph 图形生成</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172056416-1575771036.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172056416-1575771036.png" />
        </a>
    </p>
<h2 id="四">四、</h2>
<h3 id="1官方的-share-分享网站">1、官方的 share 分享网站</h3>
<p><a href="https://share.zabbix.com/zabbix-tools-and-utilities">https://share.zabbix.com/zabbix-tools-and-utilities</a></p>
<ul>
<li>例如：我们要实现监控Nginx ，我们查找一个模板</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172057635-1089716709.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172057635-1089716709.png" />
        </a>
    </p>
<ul>
<li>就以这个模板为例</li>
</ul>
<p>​                                          
        <a data-fancybox="gallery" href="assets/1216496-20171226172058182-128310444.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172058182-128310444.png" />
        </a>
    </p>
<h3 id="2在node1-上使用此模板">2、在node1 上使用此模板</h3>
<h4 id="1安装配置-nginx">1、安装配置 nginx</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum -y install nginx</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/nginx/nginx.conf  # 按照网页的操作指示</span>
location /stub_status <span style="color:#000;font-weight:bold">{</span>
        stub_status on;
        access_log off;
    <span style="color:#998;font-style:italic">#    allow 127.0.0.1;   #为了操作方便，我取消的访问控制</span>
    <span style="color:#998;font-style:italic">#    deny all;</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172058510-1149178016.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172058510-1149178016.png" />
        </a>
    </p>
<p>2、启动服务</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl restart nginx</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="2下载模板所依赖的脚本">2、下载模板所依赖的脚本</h4>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172058823-57198051.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172058823-57198051.png" />
        </a>
    </p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># mkdir -p /srv/zabbix/libexec/</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># cd /srv/zabbix/libexec/</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># wget https://raw.githubusercontent.com/oscm/zabbix/master/nginx/nginx.sh # 从网页上获取脚本</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># chmod +x nginx.sh # 加执行权限</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="3配置-agent-的用户参数-userparameter">3、配置 agent 的用户参数 UserParameter</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># cd /etc/zabbix/zabbix_agentd.d/</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># wget https://raw.githubusercontent.com/oscm/zabbix/master/nginx/userparameter_nginx.conf # 很短自己写也行</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172059073-397108138.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172059073-397108138.png" />
        </a>
    </p>
<h4 id="4在-windows-上下载模板并导入server-的模板中">4、在 windows 上下载模板并导入server 的模板中</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># wget https://raw.githubusercontent.com/oscm/zabbix/master/nginx/zbx_export_templates.xml</span>
</code></pre></td></tr></table>
</div>
</div><p>可以现在linux上下载，再sz 导出到 windows 上</p>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172059291-1133694346.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172059291-1133694346.png" />
        </a>
    </p>
<h5 id="1导入下载的模板">1、导入下载的模板</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172059635-1317185355.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172059635-1317185355.png" />
        </a>
    </p>
<h5 id="2主机-node1-链接这个模板">2、主机 node1 链接这个模板</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172100041-1015144646.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172100041-1015144646.png" />
        </a>
    </p>
<h5 id="3模板生效">3、模板生效</h5>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172100323-635966866.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172100323-635966866.png" />
        </a>
    </p>
<h2 id="五zabbix-server-监控自己数据库nginx">五、Zabbix-server 监控自己，数据库，nginx</h2>
<h3 id="1下载安装配置agent">1、下载安装配置agent</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/zabbix/zabbix_agentd.conf</span>
<span style="color:#008080">EnableRemoteCommands</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span>    允许远程命令
<span style="color:#008080">LogRemoteCommands</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span>    记录远程命令
<span style="color:#008080">Server</span><span style="color:#000;font-weight:bold">=</span>127.0.0.1   <span style="color:#998;font-style:italic">#建议真实ip地址</span>
<span style="color:#008080">ServerActive</span><span style="color:#000;font-weight:bold">=</span>127.0.0.1
<span style="color:#008080">Hostname</span><span style="color:#000;font-weight:bold">=</span>server.qfedu.com
</code></pre></td></tr></table>
</div>
</div><h3 id="2自动生成-zabbix-server-的主机">2、自动生成 Zabbix server 的主机</h3>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172101526-749330259.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172101526-749330259.png" />
        </a>
    </p>
<h3 id="3在主机中添加模板">3、在主机中添加模板</h3>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172101885-2112581492.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172101885-2112581492.png" />
        </a>
    </p>
<h3 id="4启用zabbix-server">4、启用Zabbix server</h3>
<p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172102370-823261452.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172102370-823261452.png" />
        </a>
    </p>
<h3 id="5监控到数据">5、监控到数据</h3>
<h4 id="zabbix_agent-客户端操作">zabbix_agent 客户端操作</h4>
<h4 id="1mysql-创建-zabbix-账号连接本地mysql">1、mysql 创建 zabbix 账号连接本地mysql</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">mysql&gt; GRANT ALL ON *.* TO <span style="color:#d14">&#39;zabbix&#39;</span>@<span style="color:#d14">&#39;localhost&#39;</span> IDENTIFIED BY <span style="color:#d14">&#39;123456&#39;</span>;
mysql&gt; FLUSH PRIVILEGES;
</code></pre></td></tr></table>
</div>
</div><p>2、在 zabbix_agentd 创建 .my.cnf （用户名密码登录配置文件）</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># cat  /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf  # 获取登录配置文件创建路径</span>
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># mkdir -p /var/lib/zabbix</span>
<span style="color:#998;font-style:italic"># 在/var/lib/zabbix下创建(隐藏).my.cnf</span>
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># cat ./.my.cnf</span>
 <span style="color:#000;font-weight:bold">[</span>client<span style="color:#000;font-weight:bold">]</span>
 <span style="color:#008080">user</span><span style="color:#000;font-weight:bold">=</span>zabbix
 <span style="color:#008080">password</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">123456</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1216496-20171226172102698-926445046.png">
            <img class="mx-auto" alt="img" src="assets/1216496-20171226172102698-926445046.png" />
        </a>
    </p>
<h2 id="六">六、</h2>
<h3 id="1申请企业微信">1、申请企业微信</h3>
<h4 id="1填写注册信息">1、填写注册信息</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616131755799-1581514954519.png">
            <img class="mx-auto" alt="img" src="assets/20180616131755799-1581514954519.png" />
        </a>
    </p>
<h3 id="2配置微信企业号">2、配置微信企业号</h3>
<h4 id="1创建告警组然后把接受消息人加进来">1、创建告警组，然后把接受消息人加进来</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616132217589-1581514954520.png">
            <img class="mx-auto" alt="img" src="assets/20180616132217589-1581514954520.png" />
        </a>
    </p>
<h4 id="2记录账号名称等下填写接收人信息需要用到">2、记录账号名称，等下填写接收人信息需要用到</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180805151546815-1581514954520.png">
            <img class="mx-auto" alt="img" src="assets/20180805151546815-1581514954520.png" />
        </a>
    </p>
<h4 id="3点击我的企业查看企业信息要记录企业corpid">3、点击我的企业，查看企业信息，要记录企业CorpID</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616132724160-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616132724160-1581514954521.png" />
        </a>
    </p>
<h4 id="4点击企业应用创建应用">4、点击企业应用，创建应用</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616132943249-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616132943249-1581514954521.png" />
        </a>
    </p>
<h4 id="5填写信息和通知用户组">5、填写信息和通知用户组</h4>
<p>
        <a data-fancybox="gallery" href="assets/2018061613311477-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/2018061613311477-1581514954521.png" />
        </a>
    </p>
<h4 id="6创建完记录agentld和secret">6、创建完，记录Agentld和Secret</h4>
<p>
        <a data-fancybox="gallery" href="assets/2018061613331047-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/2018061613331047-1581514954521.png" />
        </a>
    </p>
<h3 id="3配置zabbix服务器">3、配置zabbix服务器</h3>
<h4 id="1首先确认已经记录的信息">1、首先确认已经记录的信息</h4>
<p>告警组用户的账号，企业CorpID和创建应用的Secret、Agentld</p>
<h4 id="2修改zabbixconf">2、修改zabbix.conf</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@lqfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># grep alertscripts /etc/zabbix/zabbix_server.conf </span>
<span style="color:#998;font-style:italic"># AlertScriptsPath=${datadir}/zabbix/alertscripts</span>
<span style="color:#008080">AlertScriptsPath</span><span style="color:#000;font-weight:bold">=</span>/usr/lib/zabbix/alertscripts
我们设置zabbix默认脚本路径，这样在web端就可以获取到脚本
</code></pre></td></tr></table>
</div>
</div><h4 id="3下载并设置脚本">3、下载并设置脚本</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@lqfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># cd /usr/lib/zabbix/alertscripts/</span>
<span style="color:#000;font-weight:bold">[</span>root@lqfedu.com alertscripts<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># wget https://raw.githubusercontent.com/OneOaaS/weixin-alert/master/weixin_linux_amd64</span>
<span style="color:#000;font-weight:bold">[</span>root@lqfedu.com alertscripts<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># mv weixin_linux_amd64 wechat</span>
<span style="color:#000;font-weight:bold">[</span>root@lqfedu.com alertscripts<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># chmod 755 wechat </span>
<span style="color:#000;font-weight:bold">[</span>root@lqfedu.com alertscripts<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># chown zabbix:zabbix wechat </span>
</code></pre></td></tr></table>
</div>
</div><h4 id="4执行脚本进行测试">4、执行脚本进行测试</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@lqfedu.com alertscripts<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># ./wechat --corpid=xxx --corpsecret=xxx --msg=&#34;您好，告警测试&#34; --user=用户账号 --agentid=xxx</span>
<span style="color:#000;font-weight:bold">{</span><span style="color:#d14">&#34;errcode&#34;</span>:0,<span style="color:#d14">&#34;errmsg&#34;</span>:<span style="color:#d14">&#34;ok&#34;</span>,<span style="color:#d14">&#34;invaliduser&#34;</span>:<span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/20180616134501823-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616134501823-1581514954521.png" />
        </a>
    </p>
<p>提示：</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">-corpid<span style="color:#000;font-weight:bold">=</span> 我们企业里面的id
--corpsecret<span style="color:#000;font-weight:bold">=</span> 这里就是我们Secret里面的id
-msg<span style="color:#000;font-weight:bold">=</span> 内容
-user<span style="color:#000;font-weight:bold">=</span>我们邀请用户的账号
</code></pre></td></tr></table>
</div>
</div><p>因为脚本是编译过的，无法进行编辑，我们可以使用 ./wechat -h or &ndash;help 查看</p>
<h3 id="4zabbix-web页面配置告警信息">4、zabbix web页面配置告警信息</h3>
<h4 id="1管理-报警媒介类型-创建告警媒介">1、管理-报警媒介类型-创建告警媒介</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616135048574-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616135048574-1581514954521.png" />
        </a>
    </p>
<h4 id="2填写报警媒介信息">2、填写报警媒介信息</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616135352989-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616135352989-1581514954521.png" />
        </a>
    </p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">--corpid<span style="color:#000;font-weight:bold">=</span>我们企业里面的id
--corpsecret<span style="color:#000;font-weight:bold">=</span>这里就是我们Secret里面的id
--agentid<span style="color:#000;font-weight:bold">=</span> Agentld ID
--user<span style="color:#000;font-weight:bold">={</span>ALERT.SENDTO<span style="color:#000;font-weight:bold">}</span>
--msg<span style="color:#000;font-weight:bold">={</span>ALERT.MESSAGE<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="3设置告警用户">3、设置告警用户</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616135636811-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616135636811-1581514954521.png" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="assets/20180616140000905-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616140000905-1581514954521.png" />
        </a>
    </p>
<h4 id="4设置告警动作">4、设置告警动作</h4>
<p>
        <a data-fancybox="gallery" href="assets/20180616140122839-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616140122839-1581514954521.png" />
        </a>
    </p>
<h5 id="1动作信息">1、动作信息</h5>
<p>
        <a data-fancybox="gallery" href="assets/20180616140240794-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616140240794-1581514954521.png" />
        </a>
    </p>
<h5 id="2填写告警时候操作信息">2、填写告警时候操作信息</h5>
<p>
        <a data-fancybox="gallery" href="assets/20180616141444154-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616141444154-1581514954521.png" />
        </a>
    </p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">故障告警:<span style="color:#000;font-weight:bold">{</span>TRIGGER.STATUS<span style="color:#000;font-weight:bold">}</span>: <span style="color:#000;font-weight:bold">{</span>TRIGGER.NAME<span style="color:#000;font-weight:bold">}</span> 
告警主机:<span style="color:#000;font-weight:bold">{</span>HOST.NAME<span style="color:#000;font-weight:bold">}</span> 
主机地址:<span style="color:#000;font-weight:bold">{</span>HOST.IP<span style="color:#000;font-weight:bold">}</span> 
告警时间:<span style="color:#000;font-weight:bold">{</span>EVENT.DATE<span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">{</span>EVENT.TIME<span style="color:#000;font-weight:bold">}</span> 
告警等级:<span style="color:#000;font-weight:bold">{</span>TRIGGER.SEVERITY<span style="color:#000;font-weight:bold">}</span> 
告警信息:<span style="color:#000;font-weight:bold">{</span>TRIGGER.NAME<span style="color:#000;font-weight:bold">}</span> 
问题详情:<span style="color:#000;font-weight:bold">{</span>ITEM.NAME<span style="color:#000;font-weight:bold">}</span>:<span style="color:#000;font-weight:bold">{</span>ITEM.VALUE<span style="color:#000;font-weight:bold">}</span> 
事件代码:<span style="color:#000;font-weight:bold">{</span>EVENT.ID<span style="color:#000;font-weight:bold">}</span> 
</code></pre></td></tr></table>
</div>
</div><h5 id="3填写恢复操作信息">3、填写恢复操作信息</h5>
<p>
        <a data-fancybox="gallery" href="assets/20180616141452375-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/20180616141452375-1581514954521.png" />
        </a>
    </p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">故障解除:<span style="color:#000;font-weight:bold">{</span>TRIGGER.STATUS<span style="color:#000;font-weight:bold">}</span>: <span style="color:#000;font-weight:bold">{</span>TRIGGER.NAME<span style="color:#000;font-weight:bold">}</span> 
恢复主机:<span style="color:#000;font-weight:bold">{</span>HOST.NAME<span style="color:#000;font-weight:bold">}</span> 
主机地址:<span style="color:#000;font-weight:bold">{</span>HOST.IP<span style="color:#000;font-weight:bold">}</span> 
恢复时间:<span style="color:#000;font-weight:bold">{</span>EVENT.DATE<span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">{</span>EVENT.TIME<span style="color:#000;font-weight:bold">}</span> 
恢复等级:<span style="color:#000;font-weight:bold">{</span>TRIGGER.SEVERITY<span style="color:#000;font-weight:bold">}</span> 
恢复信息:<span style="color:#000;font-weight:bold">{</span>TRIGGER.NAME<span style="color:#000;font-weight:bold">}</span> 
问题详情:<span style="color:#000;font-weight:bold">{</span>ITEM.NAME<span style="color:#000;font-weight:bold">}</span>:<span style="color:#000;font-weight:bold">{</span>ITEM.VALUE<span style="color:#000;font-weight:bold">}</span> 
事件代码:<span style="color:#000;font-weight:bold">{</span>EVENT.ID<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="5手动触发告警测试微信接收信息">5、手动触发告警，测试微信接收信息</h3>
<ul>
<li>在agent端使用yum安装一下redis：</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum install redis -y</span>
</code></pre></td></tr></table>
</div>
</div><ul>
<li>修改配置文件</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /etc/redis.conf </span>
<span style="color:#0086b3">bind</span> 0.0.0.0        <span style="color:#998;font-style:italic">#不做任何认证操作</span>
</code></pre></td></tr></table>
</div>
</div><ul>
<li>修改完成以后启动服务并检查端口：</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start redis</span>
<span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># ss -nutlp | grep redis</span>
tcp    LISTEN     <span style="color:#099">0</span>      <span style="color:#099">128</span>       *:6379                  *:*                   users:<span style="color:#000;font-weight:bold">((</span><span style="color:#d14">&#34;redis-server&#34;</span>,pid<span style="color:#000;font-weight:bold">=</span>5250,fd<span style="color:#000;font-weight:bold">=</span>4<span style="color:#000;font-weight:bold">))</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="1定义监控项">1、定义监控项</h4>
<ul>
<li>进入 配置 &mdash;&gt; 主机 &mdash;&gt; node1 &mdash;&gt; 监控项（items）&mdash;&gt; 创建监控项</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1204916-20171202113104229-190921891-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113104229-190921891-1581514954521.png" />
        </a>
    </p>
<ul>
<li>填写完毕以后点击下方的添加。</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1204916-20171202113113058-1658955278-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113113058-1658955278-1581514954521.png" />
        </a>
    </p>
<ul>
<li>该监控项已成功添加。查看一下他的值：检测中 &mdash;&gt; 最新数据</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1204916-20171202113122433-2129349774-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113122433-2129349774-1581514954521.png" />
        </a>
    </p>
<h4 id="2定义触发器">2、定义触发器</h4>
<ul>
<li>进入 配置 &mdash;&gt; 主机 &mdash;&gt; node1 &mdash;&gt; 触发器（trigger）&mdash;&gt; 创建触发器</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1204916-20171202113131761-6927531-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113131761-6927531-1581514954521.png" />
        </a>
    </p>
<ul>
<li>填写完毕以后点击下方的添加</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1204916-20171202113142604-1237551286-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113142604-1237551286-1581514954521.png" />
        </a>
    </p>
<ul>
<li>
<p>该触发器已成功添加。查看：监测中 &mdash;&gt; 最新数据

        <a data-fancybox="gallery" href="assets/1204916-20171202113150479-1838545643-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113150479-1838545643-1581514954521.png" />
        </a>
    </p>
</li>
<li>
<p>手动关闭 redis 服务来检测：</p>
</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl stop redis.service</span>
</code></pre></td></tr></table>
</div>
</div><ul>
<li>进入监测中 &mdash;&gt; 问题</li>
</ul>
<p>
        <a data-fancybox="gallery" href="assets/1204916-20171202113158901-587145295-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113158901-587145295-1581514954521.png" />
        </a>
    </p>
<ul>
<li>已经显示的是问题了。并且有持续的时间，当服务被打开，会转为已解决状态：</li>
</ul>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@node1 ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start redis.service </span>
</code></pre></td></tr></table>
</div>
</div><p>
        <a data-fancybox="gallery" href="assets/1204916-20171202113209698-2146797322-1581514954521.png">
            <img class="mx-auto" alt="img" src="assets/1204916-20171202113209698-2146797322-1581514954521.png" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="assets/%e6%97%a0%e6%a0%87%e9%a2%98-1555110317243-1581514954521.png">
            <img class="mx-auto" alt="无标题" src="assets/%e6%97%a0%e6%a0%87%e9%a2%98-1555110317243-1581514954521.png" />
        </a>
    </p>
<h3 id="6微信客户端检测">6、微信客户端检测</h3>
<h2 id="七zabbix-调优">七、Zabbix 调优</h2>
<h3 id="1调优">1、调优</h3>
<h4 id="1database">1、Database：</h4>
<ul>
<li>
<p>历史数据不要保存太长时长；</p>
</li>
<li>
<p>尽量让数据缓存在数据库服务器的内存中；</p>
</li>
</ul>
<p>2、触发器表达式：</p>
<ul>
<li>
<p>减少使用聚合函数min(), max(), avg()；尽量使用last()，nodata()，因为聚合函数，要运算</p>
</li>
<li>
<p>数据收集：polling较慢(减少使用SNMP/agentless/agent）；<strong>尽量使用trapping（agent(active）主动监控）；</strong></p>
</li>
<li>
<p>数据类型：文本型数据处理速度较慢；<strong>尽量少</strong>收集类型为<strong>文本</strong> text或string类型的数据；<strong>多使用</strong>类型为numeric <strong>数值型数据</strong> 的；</p>
</li>
</ul>
<h3 id="2zabbix服务器的进程">2、zabbix服务器的进程</h3>
<h4 id="1服务器组件的数量">1、服务器组件的数量；</h4>
<ul>
<li>
<p>alerter, discoverer, escalator, http poller, hourekeeper, icmp pinger, ipmi polller, poller, trapper, configration syncer, &hellip;</p>
</li>
<li>
<p>StartPollers=60</p>
</li>
<li>
<p>StartPingers=10</p>
</li>
</ul>
<p>　　&hellip;</p>
<ul>
<li>StartDBSyncer=5</li>
</ul>
<p>　　&hellip;</p>
<h4 id="2设定合理的缓存大小">2、设定合理的缓存大小</h4>
<ul>
<li>
<p>CacheSize=8M</p>
</li>
<li>
<p>HistoryCacheSize=16M</p>
</li>
<li>
<p>HistoryIndexCacheSize=4M</p>
</li>
<li>
<p>TrendCacheSize=4M</p>
</li>
<li>
<p>ValueCacheSize=4M</p>
</li>
</ul>
<h4 id="3数据库优化">3、数据库优化</h4>
<p>　　分表：</p>
<p>　　　　history_*</p>
<p>　　　　trends*</p>
<p>　　　　events*</p>
<h3 id="3其它解决方案">3、其它解决方案</h3>
<ul>
<li>
<p>grafana：展示</p>
</li>
<li>
<p>collectd：收集</p>
</li>
<li>
<p>influxdb：存储</p>
</li>
</ul>
<h3 id="4grafanacollectdinfluxdb">4、grafana+collectd+influxdb</h3>
<h4 id="5prometheus">5、prometheus：</h4>
<ul>
<li>
<p>exporter：收集</p>
</li>
<li>
<p>alertmanager:</p>
</li>
<li>
<p>grafana：展示</p>
</li>
</ul>
<h2 id="八zabbix监控实战-tomcat监控">八、Zabbix监控实战-Tomcat监控</h2>
<h3 id="1方法一开发java监控页面">1、方法一：开发java监控页面</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com tomcat8_1<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># cat /application/tomcat/webapps/memtest/meminfo.jsp </span>
&lt;%
Runtime <span style="color:#008080">rtm</span> <span style="color:#000;font-weight:bold">=</span> Runtime.getRuntime<span style="color:#000;font-weight:bold">()</span>;
long <span style="color:#008080">mm</span> <span style="color:#000;font-weight:bold">=</span> rtm.maxMemory<span style="color:#000;font-weight:bold">()</span>/1024/1024;
long <span style="color:#008080">tm</span> <span style="color:#000;font-weight:bold">=</span> rtm.totalMemory<span style="color:#000;font-weight:bold">()</span>/1024/1024;
long <span style="color:#008080">fm</span> <span style="color:#000;font-weight:bold">=</span> rtm.freeMemory<span style="color:#000;font-weight:bold">()</span>/1024/1024;

out.println<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JVM memory detail info :&lt;br&gt;&#34;</span><span style="color:#000;font-weight:bold">)</span>;
out.println<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;Max memory:&#34;</span>+mm+<span style="color:#d14">&#34;MB&#34;</span>+<span style="color:#d14">&#34;&lt;br&gt;&#34;</span><span style="color:#000;font-weight:bold">)</span>;
out.println<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;Total memory:&#34;</span>+tm+<span style="color:#d14">&#34;MB&#34;</span>+<span style="color:#d14">&#34;&lt;br&gt;&#34;</span><span style="color:#000;font-weight:bold">)</span>;
out.println<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;Free memory:&#34;</span>+fm+<span style="color:#d14">&#34;MB&#34;</span>+<span style="color:#d14">&#34;&lt;br&gt;&#34;</span><span style="color:#000;font-weight:bold">)</span>;
out.println<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;Available memory can be used is :&#34;</span>+<span style="color:#000;font-weight:bold">(</span>mm+fm-tm<span style="color:#000;font-weight:bold">)</span>+<span style="color:#d14">&#34;MB&#34;</span>+<span style="color:#d14">&#34;&lt;br&gt;&#34;</span><span style="color:#000;font-weight:bold">)</span>;
%&gt;
</code></pre></td></tr></table>
</div>
</div><h3 id="2方法二使用jps命令进行监控">2、方法二：使用jps命令进行监控</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">9
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># jps -lvm</span>

<span style="color:#099">31906</span> org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_1/conf/logging.properties -Djava.util.logging.manager<span style="color:#000;font-weight:bold">=</span>org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_1/endorsed -Dcatalina.base<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_1 -Dcatalina.home<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_1 -Djava.io.tmpdir<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_1/temp

<span style="color:#099">31812</span> org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file<span style="color:#000;font-weight:bold">=</span>/application/tomcat/conf/logging.properties -Djava.util.logging.manager<span style="color:#000;font-weight:bold">=</span>org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs<span style="color:#000;font-weight:bold">=</span>/application/tomcat/endorsed -Dcatalina.base<span style="color:#000;font-weight:bold">=</span>/application/tomcat -Dcatalina.home<span style="color:#000;font-weight:bold">=</span>/application/tomcat -Djava.io.tmpdir<span style="color:#000;font-weight:bold">=</span>/application/tomcat/temp

<span style="color:#099">31932</span> org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_2/conf/logging.properties -Djava.util.logging.manager<span style="color:#000;font-weight:bold">=</span>org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_2/endorsed -Dcatalina.base<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_2 -Dcatalina.home<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_2 -Djava.io.tmpdir<span style="color:#000;font-weight:bold">=</span>/application/tomcat8_2/temp

<span style="color:#099">32079</span> sun.tools.jps.Jps -lvm -Denv.class.path<span style="color:#000;font-weight:bold">=</span>.:/application/jdk/lib:/application/jdk/jre/lib:/application/jdk/lib/tools.jar -Dapplication.home<span style="color:#000;font-weight:bold">=</span>/application/jdk1.8.0_60 -Xms8m
</code></pre></td></tr></table>
</div>
</div><h3 id="3tomcat-远程监控功能">3、Tomcat 远程监控功能</h3>
<h4 id="1修改配置文件开启远程监控">1、修改配置文件，开启远程监控</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># vim /application/tomcat8_1/bin/catalina.sh +97</span>
<span style="color:#008080">CATALINA_OPTS</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;</span><span style="color:#008080">$CATALINA_OPTS</span><span style="color:#d14">
</span><span style="color:#d14">-Dcom.sun.management.jmxremote 
</span><span style="color:#d14">-Dcom.sun.management.jmxremote.port=12345  
</span><span style="color:#d14">-Dcom.sun.management.jmxremote.authenticate=false 
</span><span style="color:#d14">-Dcom.sun.management.jmxremote.ssl=false 
</span><span style="color:#d14">-Djava.rmi.server.hostname=10.0.0.17&#34;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="2重启服务检查12345端口是否开启">2、重启服务，检查12345端口是否开启</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># /application/tomcat8_1/bin/shutdown.sh </span>
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># /application/tomcat8_1/bin/startup.sh </span>
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># netstat -tunlp|grep 12345</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="3-检查端口">3、 检查端口</h4>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># netstat -tunlp|grep 12345</span>
tcp6       <span style="color:#099">0</span>      <span style="color:#099">0</span> :::12345           :::*          LISTEN      33158/java  
</code></pre></td></tr></table>
</div>
</div><p>4、在windows上监控tomcat</p>
<p><strong>注意：windwos需要安装jdk环境！</strong></p>
<p>查考：http://www.oracle.com/technetwork/java/javase/downloads/index.html</p>
<h5 id="1软件路径">1、软件路径</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cmd" data-lang="cmd">C:<span style="color:#900;font-weight:bold">\Program</span><span style="color:#998;font-style:italic"> Files\Java\jdk1.8.0_31\bin</span>
jconsole.exe   jvisualvm.exe
</code></pre></td></tr></table>
</div>
</div><h5 id="2jconsoleexe-使用说明">2、jconsole.exe 使用说明</h5>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127162727784-599308853.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127162727784-599308853.png" />
        </a>
    </p>
<p>​         连接成功即可进行监控，连接的时候注意端口信息。</p>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127162738565-738384915.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127162738565-738384915.png" />
        </a>
    </p>
<h6 id="3jvisualvmexe-使用说明">3、jvisualvm.exe 使用说明</h6>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127162750784-48883054.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127162750784-48883054.png" />
        </a>
    </p>
<p>​         <strong>输入ip地址</strong></p>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127162759081-1663450024.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127162759081-1663450024.png" />
        </a>
    </p>
<p>​         <strong>主机添加完成，添加JMX监控</strong></p>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127162808253-922440046.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127162808253-922440046.png" />
        </a>
    </p>
<p>​            <strong>注意添加的时候输入端口信息</strong></p>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127162819378-1066040054.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127162819378-1066040054.png" />
        </a>
    </p>
<p>​         添加完成后就能够多tomcat程序进行监控。</p>
<h3 id="4zabbix-监控-tomcat-程序">4、zabbix 监控 tomcat 程序</h3>
<h5 id="1zabbix-服务端安装配置-java监控服务">1、zabbix 服务端安装配置 java监控服务</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># yum install zabbix-java-gateway -y</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="2查看配置文件">2、查看配置文件</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">配置文件路径：/etc/zabbix/zabbix_java_gateway.conf
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># sed -i -e &#39;220a JavaGateway=127.0.0.1&#39; -e &#39;236a StartJavaPollers=5&#39;  /etc/zabbix/zabbix_server.conf</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="3启动zabbix-java-gateway服务与zabbix服务">3、启动zabbix-java-gateway服务，与zabbix服务</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl start zabbix-java-gateway.service</span>
<span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># systemctl restart zabbix-server.service</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="4检查java端口是否开启">4、检查java端口是否开启</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># netstat -lntup |grep java</span>
tcp6       <span style="color:#099">0</span>      <span style="color:#099">0</span> :::10052   :::*    LISTEN      72971/java  
</code></pre></td></tr></table>
</div>
</div><h5 id="5检查java进程是否存在">5、检查java进程是否存在</h5>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000;font-weight:bold">[</span>root@qfedu.com ~<span style="color:#000;font-weight:bold">]</span><span style="color:#998;font-style:italic"># ps -ef |grep [j]ava</span>
zabbix    <span style="color:#099">72971</span>      <span style="color:#099">1</span>  <span style="color:#099">0</span> 11:29 ?        00:00:00 java -server -Dlogback.configurationFile<span style="color:#000;font-weight:bold">=</span>/etc/zabbix/zabbix_java_gateway_logback.xml -classpath lib:lib/android-json-4.3_r3.1.jar:lib/logback-classic-0.9.27.jar:lib/logback-core-0.9.27.jar:lib/slf4j-api-1.6.1.jar:bin/zabbix-java-gateway-3.0.13.jar -Dzabbix.pidFile<span style="color:#000;font-weight:bold">=</span>/var/run/zabbix/zabbix_java.pid -Dzabbix.timeout<span style="color:#000;font-weight:bold">=</span><span style="color:#099">3</span> -Dsun.rmi.transport.tcp.responseTimeout<span style="color:#000;font-weight:bold">=</span><span style="color:#099">3000</span> com.zabbix.gateway.JavaGateway
zabbix    <span style="color:#099">73255</span>  <span style="color:#099">73226</span>  <span style="color:#099">0</span> 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller <span style="color:#998;font-style:italic">#1 [got 0 values in 0.000002 sec, idle 5 sec]</span>
zabbix    <span style="color:#099">73256</span>  <span style="color:#099">73226</span>  <span style="color:#099">0</span> 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller <span style="color:#998;font-style:italic">#2 [got 0 values in 0.000002 sec, idle 5 sec]</span>
zabbix    <span style="color:#099">73257</span>  <span style="color:#099">73226</span>  <span style="color:#099">0</span> 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller <span style="color:#998;font-style:italic">#3 [got 0 values in 0.000002 sec, idle 5 sec]</span>
zabbix    <span style="color:#099">73258</span>  <span style="color:#099">73226</span>  <span style="color:#099">0</span> 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller <span style="color:#998;font-style:italic">#4 [got 0 values in 0.000002 sec, idle 5 sec]</span>
zabbix    <span style="color:#099">73259</span>  <span style="color:#099">73226</span>  <span style="color:#099">0</span> 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller <span style="color:#998;font-style:italic">#5 [got 0 values in 0.000004 sec, idle 5 sec]</span>
</code></pre></td></tr></table>
</div>
</div><h5 id="6web界面添加">6、web界面添加</h5>
<h6 id="1添加主机">1、添加主机</h6>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127163059878-505035611.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127163059878-505035611.png" />
        </a>
    </p>
<h6 id="2主机管理模板注意是jmx模板">2、主机管理模板，注意是JMX模板</h6>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127163107737-761922553.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127163107737-761922553.png" />
        </a>
    </p>
<h6 id="3监控完成">3、监控完成</h6>
<p>
        <a data-fancybox="gallery" href="assets/1190037-20171127163113909-1086285598.png">
            <img class="mx-auto" alt="img" src="assets/1190037-20171127163113909-1086285598.png" />
        </a>
    </p>
<h3 id="5排除-tomcat-故障步骤">5、排除 tomcat 故障步骤</h3>
<h6 id="1查看-catalinaout">1、查看 catalina.out</h6>
<h6 id="2使用-sh-show-busy-java-threadssh-脚本进行检测">2、使用 sh show-busy-java-threads.sh 脚本进行检测</h6>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 62
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 63
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 64
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 65
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 66
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 67
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 68
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 69
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 70
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 71
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 72
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 73
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 74
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 75
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 76
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 77
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 78
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 79
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 80
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 81
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 82
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 83
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 84
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 85
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 86
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 87
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 88
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 89
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 90
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 91
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 92
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 93
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 94
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 95
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 96
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 97
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 98
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 99
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">100
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">101
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">102
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">103
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">104
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">105
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">106
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">107
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">108
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">109
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">110
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">111
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">112
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">113
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">114
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">115
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">116
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">117
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">118
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">119
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">120
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">121
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">122
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">123
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">124
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">125
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">126
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">127
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">128
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">129
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">130
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">131
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">132
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">133
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">134
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">135
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">136
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">137
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">138
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">139
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">140
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">141
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">142
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">143
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">144
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">145
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">146
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">147
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">148
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#999;font-weight:bold;font-style:italic">#!/bin/bash
</span><span style="color:#999;font-weight:bold;font-style:italic"></span><span style="color:#998;font-style:italic"># @Function</span>
<span style="color:#998;font-style:italic"># Find out the highest cpu consumed threads of java, and print the stack of these threads.</span>
<span style="color:#998;font-style:italic">#</span>
<span style="color:#998;font-style:italic"># @Usage</span>
<span style="color:#998;font-style:italic">#   $ ./show-busy-java-threads.sh</span>
<span style="color:#998;font-style:italic">#</span>
<span style="color:#998;font-style:italic"># @author Jerry Lee</span>

<span style="color:#0086b3">readonly</span> <span style="color:#008080">PROG</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">`</span>basename <span style="color:#008080">$0</span><span style="color:#d14">`</span>
<span style="color:#0086b3">readonly</span> -a <span style="color:#008080">COMMAND_LINE</span><span style="color:#000;font-weight:bold">=(</span><span style="color:#d14">&#34;</span><span style="color:#008080">$0</span><span style="color:#d14">&#34;</span> <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span><span style="color:#000;font-weight:bold">)</span>

usage<span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
    cat <span style="color:#d14">&lt;&lt;EOF
</span><span style="color:#d14">Usage: ${PROG} [OPTION]...
</span><span style="color:#d14">Find out the highest cpu consumed threads of java, and print the stack of these threads.
</span><span style="color:#d14">Example: ${PROG} -c 10
</span><span style="color:#d14">
</span><span style="color:#d14">Options:
</span><span style="color:#d14">    -p, --pid       find out the highest cpu consumed threads from the specifed java process,
</span><span style="color:#d14">                    default from all java process.
</span><span style="color:#d14">    -c, --count     set the thread count to show, default is 5
</span><span style="color:#d14">    -h, --help      display this help and exit
</span><span style="color:#d14">EOF</span>
    <span style="color:#0086b3">exit</span> <span style="color:#008080">$1</span>
<span style="color:#000;font-weight:bold">}</span>

<span style="color:#0086b3">readonly</span> <span style="color:#008080">ARGS</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">`</span>getopt -n <span style="color:#d14">&#34;</span><span style="color:#008080">$PROG</span><span style="color:#d14">&#34;</span> -a -o c:p:h -l count:,pid:,help -- <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span><span style="color:#d14">`</span>
<span style="color:#000;font-weight:bold">[</span> <span style="color:#008080">$?</span> -ne <span style="color:#099">0</span> <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> usage <span style="color:#099">1</span>
<span style="color:#0086b3">eval</span> <span style="color:#0086b3">set</span> -- <span style="color:#d14">&#34;</span><span style="color:#d14">${</span><span style="color:#008080">ARGS</span><span style="color:#d14">}</span><span style="color:#d14">&#34;</span>

<span style="color:#000;font-weight:bold">while</span> true; <span style="color:#000;font-weight:bold">do</span>
    <span style="color:#000;font-weight:bold">case</span> <span style="color:#d14">&#34;</span><span style="color:#008080">$1</span><span style="color:#d14">&#34;</span> in
    -c|--count<span style="color:#000;font-weight:bold">)</span>
        <span style="color:#008080">count</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;</span><span style="color:#008080">$2</span><span style="color:#d14">&#34;</span>
        <span style="color:#0086b3">shift</span> <span style="color:#099">2</span>
        ;;
    -p|--pid<span style="color:#000;font-weight:bold">)</span>
        <span style="color:#008080">pid</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;</span><span style="color:#008080">$2</span><span style="color:#d14">&#34;</span>
        <span style="color:#0086b3">shift</span> <span style="color:#099">2</span>
        ;;
    -h|--help<span style="color:#000;font-weight:bold">)</span>
        usage
        ;;
    --<span style="color:#000;font-weight:bold">)</span>
        <span style="color:#0086b3">shift</span>
        <span style="color:#0086b3">break</span>
        ;;
    <span style="color:#000;font-weight:bold">esac</span>
<span style="color:#000;font-weight:bold">done</span>
<span style="color:#008080">count</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">${</span><span style="color:#008080">count</span><span style="color:#000;font-weight:bold">:-</span><span style="color:#008080">5</span><span style="color:#d14">}</span>

redEcho<span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#000;font-weight:bold">[</span> -c /dev/stdout <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#998;font-style:italic"># if stdout is console, turn on color output.</span>
        <span style="color:#0086b3">echo</span> -ne <span style="color:#d14">&#34;\033[1;31m&#34;</span>
        <span style="color:#0086b3">echo</span> -n <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span>
        <span style="color:#0086b3">echo</span> -e <span style="color:#d14">&#34;\033[0m&#34;</span>
    <span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">||</span> <span style="color:#0086b3">echo</span> <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span>
<span style="color:#000;font-weight:bold">}</span>

yellowEcho<span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#000;font-weight:bold">[</span> -c /dev/stdout <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#998;font-style:italic"># if stdout is console, turn on color output.</span>
        <span style="color:#0086b3">echo</span> -ne <span style="color:#d14">&#34;\033[1;33m&#34;</span>
        <span style="color:#0086b3">echo</span> -n <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span>
        <span style="color:#0086b3">echo</span> -e <span style="color:#d14">&#34;\033[0m&#34;</span>
    <span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">||</span> <span style="color:#0086b3">echo</span> <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span>
<span style="color:#000;font-weight:bold">}</span>

blueEcho<span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#000;font-weight:bold">[</span> -c /dev/stdout <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#998;font-style:italic"># if stdout is console, turn on color output.</span>
        <span style="color:#0086b3">echo</span> -ne <span style="color:#d14">&#34;\033[1;36m&#34;</span>
        <span style="color:#0086b3">echo</span> -n <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span>
        <span style="color:#0086b3">echo</span> -e <span style="color:#d14">&#34;\033[0m&#34;</span>
    <span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">||</span> <span style="color:#0086b3">echo</span> <span style="color:#d14">&#34;</span><span style="color:#008080">$@</span><span style="color:#d14">&#34;</span>
<span style="color:#000;font-weight:bold">}</span>

<span style="color:#998;font-style:italic"># Check the existence of jstack command!</span>
<span style="color:#000;font-weight:bold">if</span> ! which jstack &amp;&gt; /dev/null; <span style="color:#000;font-weight:bold">then</span>
    <span style="color:#000;font-weight:bold">[</span> -z <span style="color:#d14">&#34;</span><span style="color:#008080">$JAVA_HOME</span><span style="color:#d14">&#34;</span> <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">{</span>
        redEcho <span style="color:#d14">&#34;Error: jstack not found on PATH!&#34;</span>
        <span style="color:#0086b3">exit</span> <span style="color:#099">1</span>
    <span style="color:#000;font-weight:bold">}</span>
    ! <span style="color:#000;font-weight:bold">[</span> -f <span style="color:#d14">&#34;</span><span style="color:#008080">$JAVA_HOME</span><span style="color:#d14">/bin/jstack&#34;</span> <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">{</span>
        redEcho <span style="color:#d14">&#34;Error: jstack not found on PATH and </span><span style="color:#008080">$JAVA_HOME</span><span style="color:#d14">/bin/jstack file does NOT exists!&#34;</span>
        <span style="color:#0086b3">exit</span> <span style="color:#099">1</span>
    <span style="color:#000;font-weight:bold">}</span>
    ! <span style="color:#000;font-weight:bold">[</span> -x <span style="color:#d14">&#34;</span><span style="color:#008080">$JAVA_HOME</span><span style="color:#d14">/bin/jstack&#34;</span> <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">{</span>
        redEcho <span style="color:#d14">&#34;Error: jstack not found on PATH and </span><span style="color:#008080">$JAVA_HOME</span><span style="color:#d14">/bin/jstack is NOT executalbe!&#34;</span>
        <span style="color:#0086b3">exit</span> <span style="color:#099">1</span>
    <span style="color:#000;font-weight:bold">}</span>
    <span style="color:#0086b3">export</span> <span style="color:#008080">PATH</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34;</span><span style="color:#008080">$JAVA_HOME</span><span style="color:#d14">/bin:</span><span style="color:#008080">$PATH</span><span style="color:#d14">&#34;</span>
<span style="color:#000;font-weight:bold">fi</span>

<span style="color:#0086b3">readonly</span> <span style="color:#008080">uuid</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">`</span>date +%s<span style="color:#d14">`</span>_<span style="color:#d14">${</span><span style="color:#008080">RANDOM</span><span style="color:#d14">}</span>_<span style="color:#008080">$$</span>

cleanupWhenExit<span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
    rm /tmp/<span style="color:#d14">${</span><span style="color:#008080">uuid</span><span style="color:#d14">}</span>_* &amp;&gt; /dev/null
<span style="color:#000;font-weight:bold">}</span>
<span style="color:#0086b3">trap</span> <span style="color:#d14">&#34;cleanupWhenExit&#34;</span> EXIT

printStackOfThread<span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#0086b3">local</span> line
    <span style="color:#0086b3">local</span> <span style="color:#008080">count</span><span style="color:#000;font-weight:bold">=</span><span style="color:#099">1</span>
    <span style="color:#000;font-weight:bold">while</span> <span style="color:#008080">IFS</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">&#34; &#34;</span> <span style="color:#0086b3">read</span> -a line ; <span style="color:#000;font-weight:bold">do</span>
        <span style="color:#0086b3">local</span> <span style="color:#008080">pid</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">${</span><span style="color:#008080">line</span>[0]<span style="color:#d14">}</span>
        <span style="color:#0086b3">local</span> <span style="color:#008080">threadId</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">${</span><span style="color:#008080">line</span>[1]<span style="color:#d14">}</span>
        <span style="color:#0086b3">local</span> <span style="color:#008080">threadId0x</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">`</span><span style="color:#0086b3">printf</span> %x <span style="color:#d14">${</span><span style="color:#008080">threadId</span><span style="color:#d14">}</span><span style="color:#d14">`</span>
        <span style="color:#0086b3">local</span> <span style="color:#008080">user</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">${</span><span style="color:#008080">line</span>[2]<span style="color:#d14">}</span>
        <span style="color:#0086b3">local</span> <span style="color:#008080">pcpu</span><span style="color:#000;font-weight:bold">=</span><span style="color:#d14">${</span><span style="color:#008080">line</span>[4]<span style="color:#d14">}</span>

        <span style="color:#0086b3">local</span> <span style="color:#008080">jstackFile</span><span style="color:#000;font-weight:bold">=</span>/tmp/<span style="color:#d14">${</span><span style="color:#008080">uuid</span><span style="color:#d14">}</span>_<span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span>

        <span style="color:#000;font-weight:bold">[</span> ! -f <span style="color:#d14">&#34;</span><span style="color:#d14">${</span><span style="color:#008080">jstackFile</span><span style="color:#d14">}</span><span style="color:#d14">&#34;</span> <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">{</span>
            <span style="color:#000;font-weight:bold">{</span>
                <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">[</span> <span style="color:#d14">&#34;</span><span style="color:#d14">${</span><span style="color:#008080">user</span><span style="color:#d14">}</span><span style="color:#d14">&#34;</span> <span style="color:#000;font-weight:bold">==</span> <span style="color:#d14">&#34;</span><span style="color:#d14">${</span><span style="color:#008080">USER</span><span style="color:#d14">}</span><span style="color:#d14">&#34;</span> <span style="color:#000;font-weight:bold">]</span>; <span style="color:#000;font-weight:bold">then</span>
                    jstack <span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span> &gt; <span style="color:#d14">${</span><span style="color:#008080">jstackFile</span><span style="color:#d14">}</span>
                <span style="color:#000;font-weight:bold">else</span>
                    <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">[</span> <span style="color:#008080">$UID</span> <span style="color:#000;font-weight:bold">==</span> <span style="color:#099">0</span> <span style="color:#000;font-weight:bold">]</span>; <span style="color:#000;font-weight:bold">then</span>
                        sudo -u <span style="color:#d14">${</span><span style="color:#008080">user</span><span style="color:#d14">}</span> jstack <span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span> &gt; <span style="color:#d14">${</span><span style="color:#008080">jstackFile</span><span style="color:#d14">}</span>
                    <span style="color:#000;font-weight:bold">else</span>
                        redEcho <span style="color:#d14">&#34;[</span><span style="color:#000;font-weight:bold">$((</span>count++<span style="color:#000;font-weight:bold">))</span><span style="color:#d14">] Fail to jstack Busy(</span><span style="color:#d14">${</span><span style="color:#008080">pcpu</span><span style="color:#d14">}</span><span style="color:#d14">%) thread(</span><span style="color:#d14">${</span><span style="color:#008080">threadId</span><span style="color:#d14">}</span><span style="color:#d14">/0x</span><span style="color:#d14">${</span><span style="color:#008080">threadId0x</span><span style="color:#d14">}</span><span style="color:#d14">) stack of java process(</span><span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span><span style="color:#d14">) under user(</span><span style="color:#d14">${</span><span style="color:#008080">user</span><span style="color:#d14">}</span><span style="color:#d14">).&#34;</span>
                        redEcho <span style="color:#d14">&#34;User of java process(</span><span style="color:#008080">$user</span><span style="color:#d14">) is not current user(</span><span style="color:#008080">$USER</span><span style="color:#d14">), need sudo to run again:&#34;</span>
                        yellowEcho <span style="color:#d14">&#34;    sudo </span><span style="color:#d14">${</span><span style="color:#008080">COMMAND_LINE</span>[@]<span style="color:#d14">}</span><span style="color:#d14">&#34;</span>
                        <span style="color:#0086b3">echo</span>
                        <span style="color:#000;font-weight:bold">continue</span>
                    <span style="color:#000;font-weight:bold">fi</span>
                <span style="color:#000;font-weight:bold">fi</span>
            <span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">||</span> <span style="color:#000;font-weight:bold">{</span>
                redEcho <span style="color:#d14">&#34;[</span><span style="color:#000;font-weight:bold">$((</span>count++<span style="color:#000;font-weight:bold">))</span><span style="color:#d14">] Fail to jstack Busy(</span><span style="color:#d14">${</span><span style="color:#008080">pcpu</span><span style="color:#d14">}</span><span style="color:#d14">%) thread(</span><span style="color:#d14">${</span><span style="color:#008080">threadId</span><span style="color:#d14">}</span><span style="color:#d14">/0x</span><span style="color:#d14">${</span><span style="color:#008080">threadId0x</span><span style="color:#d14">}</span><span style="color:#d14">) stack of java process(</span><span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span><span style="color:#d14">) under user(</span><span style="color:#d14">${</span><span style="color:#008080">user</span><span style="color:#d14">}</span><span style="color:#d14">).&#34;</span>
                <span style="color:#0086b3">echo</span>
                rm <span style="color:#d14">${</span><span style="color:#008080">jstackFile</span><span style="color:#d14">}</span>
                <span style="color:#000;font-weight:bold">continue</span>
            <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#000;font-weight:bold">}</span>
        blueEcho <span style="color:#d14">&#34;[</span><span style="color:#000;font-weight:bold">$((</span>count++<span style="color:#000;font-weight:bold">))</span><span style="color:#d14">] Busy(</span><span style="color:#d14">${</span><span style="color:#008080">pcpu</span><span style="color:#d14">}</span><span style="color:#d14">%) thread(</span><span style="color:#d14">${</span><span style="color:#008080">threadId</span><span style="color:#d14">}</span><span style="color:#d14">/0x</span><span style="color:#d14">${</span><span style="color:#008080">threadId0x</span><span style="color:#d14">}</span><span style="color:#d14">) stack of java process(</span><span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span><span style="color:#d14">) under user(</span><span style="color:#d14">${</span><span style="color:#008080">user</span><span style="color:#d14">}</span><span style="color:#d14">):&#34;</span>
        sed <span style="color:#d14">&#34;/nid=0x</span><span style="color:#d14">${</span><span style="color:#008080">threadId0x</span><span style="color:#d14">}</span><span style="color:#d14"> /,/^</span>$<span style="color:#d14">/p&#34;</span> -n <span style="color:#d14">${</span><span style="color:#008080">jstackFile</span><span style="color:#d14">}</span>
    <span style="color:#000;font-weight:bold">done</span>
<span style="color:#000;font-weight:bold">}</span>


ps -Leo pid,lwp,user,comm,pcpu --no-headers | <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#000;font-weight:bold">[</span> -z <span style="color:#d14">&#34;</span><span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span><span style="color:#d14">&#34;</span> <span style="color:#000;font-weight:bold">]</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span>
    awk <span style="color:#d14">&#39;$4==&#34;java&#34;{print $0}&#39;</span> <span style="color:#000;font-weight:bold">||</span>
    awk -v <span style="color:#d14">&#34;pid=</span><span style="color:#d14">${</span><span style="color:#008080">pid</span><span style="color:#d14">}</span><span style="color:#d14">&#34;</span> <span style="color:#d14">&#39;$1==pid,$4==&#34;java&#34;{print $0}&#39;</span>
<span style="color:#000;font-weight:bold">}</span> | sort -k5 -r -n | head --lines <span style="color:#d14">&#34;</span><span style="color:#d14">${</span><span style="color:#008080">count</span><span style="color:#d14">}</span><span style="color:#d14">&#34;</span> | printStackOfThread
</code></pre></td></tr></table>
</div>
</div><h2 id="九zabbix-监控-php-fpm">九、zabbix 监控 php-fpm</h2>
<p>zabbix监控php-fpm主要是通过nginx配置php-fpm的状态输出页面，在正则取值.要nginx能输出php-fpm的状态首先要先修改php-fpm的配置，没有开启nginx是没有法输出php-fpm status。</p>
<h3 id="1修改文件php-fpm">1、修改文件php-fpm</h3>
<p>vim /application/php-5.5.32/etc/php-fpm.conf文件</p>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021111145530-1093315619.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021111145530-1093315619.png" />
        </a>
    </p>
<h3 id="2修改nginx配置文件">2、修改nginx配置文件</h3>
<p>vim /application/nginx/conf/extra/www.conf，在server 区块下添加一行内容</p>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021111723825-434667199.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021111723825-434667199.png" />
        </a>
    </p>
<p><strong>重启nginx</strong></p>
<h3 id="3curl-127001php_status-我们可以看到php-fpm-的状态信息">3、curl 127.0.0.1/php_status 我们可以看到php-fpm 的状态信息</h3>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021111937582-1246959624.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021111937582-1246959624.png" />
        </a>
    </p>
<table>
<thead>
<tr>
<th><strong>字段</strong></th>
<th><strong>含义</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>pool</strong></td>
<td><strong>php-fpm pool的名称，大多数情况下为www</strong></td>
</tr>
<tr>
<td><strong>process manager</strong></td>
<td><strong>进程管理方式，现今大多都为dynamic，不要使用static</strong></td>
</tr>
<tr>
<td><strong>start time</strong></td>
<td><strong>php-fpm上次启动的时间</strong></td>
</tr>
<tr>
<td><strong>start since</strong></td>
<td><strong>php-fpm已运行了多少秒</strong></td>
</tr>
<tr>
<td><strong>accepted conn</strong></td>
<td><strong>pool接收到的请求数</strong></td>
</tr>
<tr>
<td><strong>listen queue</strong></td>
<td><strong>处于等待状态中的连接数，如果不为0，需要增加php-fpm进程数</strong></td>
</tr>
<tr>
<td><strong>max listen queue</strong></td>
<td><strong>php-fpm启动到现在处于等待连接的最大数量</strong></td>
</tr>
<tr>
<td><strong>listen queue len</strong></td>
<td><strong>处于等待连接队列的套接字大小</strong></td>
</tr>
<tr>
<td><strong>idle processes</strong></td>
<td><strong>处于空闲状态的进程数</strong></td>
</tr>
<tr>
<td><strong>active processes</strong></td>
<td><strong>处于活动状态的进程数</strong></td>
</tr>
<tr>
<td><strong>total processess</strong></td>
<td><strong>进程总数</strong></td>
</tr>
<tr>
<td><strong>max active process</strong></td>
<td><strong>从php-fpm启动到现在最多有几个进程处于活动状态</strong></td>
</tr>
<tr>
<td><strong>max children reached</strong></td>
<td><strong>当pm试图启动更多的children进程时，却达到了进程数的限制，达到一次记录一次，如果不为0，需要增加php-fpm pool进程的最大数</strong></td>
</tr>
<tr>
<td><strong>slow requests</strong></td>
<td><strong>当启用了php-fpm slow-log功能时，如果出现php-fpm慢请求这个计数器会增加，一般不当的Mysql查询会触发这个值</strong></td>
</tr>
</tbody>
</table>
<h3 id="4编写监控脚本和监控文件">4、编写监控脚本和监控文件</h3>
<pre><code>vim /server/scripts/php_fpm-status.sh

#!/bin/sh
#php-fpm status
case $1 in
ping) #检测php-fpm进程是否存在
/sbin/pidof php-fpm | wc -l
;;
start_since) #提取status中的start since数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==4{print $3}'
;;
conn) #提取status中的accepted conn数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==5{print $3}'
;;
listen_queue) #提取status中的listen queue数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==6{print $3}'
;;
max_listen_queue) #提取status中的max listen queue数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==7{print $4}'
;;
listen_queue_len) #提取status中的listen queue len
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==8{print $4}'
;;
idle_processes) #提取status中的idle processes数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==9{print $3}'
;;
active_processes) #提取status中的active processes数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==10{print $3}'
;;
total_processes) #提取status中的total processess数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==11{print $3}'
;;
max_active_processes) #提取status中的max active processes数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==12{print $4}'
;;
max_children_reached) #提取status中的max children reached数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==13{print $4}'
;;
slow_requests) #提取status中的slow requests数值
/usr/bin/curl 127.0.0.1/php_status 2&gt;/dev/null | awk 'NR==14{print $3}'
;;
*)
echo &quot;Usage: $0 {conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processess|total_processes|max_active_processes|max_children_reached|slow_requests}&quot;
exit 1
;;
esac

vim /etc/zabbix/zabbix_agentd.d/test.conf

UserParameter=php_status[*],/bin/sh /server/scripts/php_fpm-status.sh $1
</code></pre><h3 id="5重启服务">5、重启服务</h3>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021115709644-600951436.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021115709644-600951436.png" />
        </a>
    </p>
<p>在服务端测试</p>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021120116630-1188327031.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021120116630-1188327031.png" />
        </a>
    </p>
<h3 id="6在web端进行配置">6、在web端进行配置</h3>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021120934677-1355519728.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021120934677-1355519728.png" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021121048666-960995697.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021121048666-960995697.png" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021121417385-1782676060.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021121417385-1782676060.png" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="/assets/1469203-20181021140310477-1768203390.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021140310477-1768203390.png" />
        </a>
    </p>
<p>这时候我们再来看最新监控数据，就可以看到我们监控的内容了
        <a data-fancybox="gallery" href="/assets/1469203-20181021143537786-1115883382.png">
            <img class="mx-auto" alt="img" src="/assets/1469203-20181021143537786-1115883382.png" />
        </a>
    </p>
<p>配置到这，我们PHP状态监控基本完成，根据需求配置相应的触发器，即可。</p>
<p>你要的模板</p>
<p>链接: <a href="https://pan.baidu.com/s/1z0IU82uGId-LH1EryyuwCw">https://pan.baidu.com/s/1z0IU82uGId-LH1EryyuwCw</a> 提取码: q6n9</p>
<h2 id="十zabbix-监控-mysql">十、zabbix 监控 mysql</h2>
<h3 id="1监控规划">1、监控规划</h3>
<p>在创建监控项之前要尽量考虑清楚要监控什么，怎么监控，监控数据如何存储，监控数据如何展现，如何处理报警等。要进行监控的系统规划需要对Zabbix很了解，这里只是提出监控的需求。</p>
<p>需求一：监控MySQL的状态，当状态发生异常，发出报警；</p>
<p>需求二：监控MySQL的操作，并用图表展现；</p>
<h3 id="2自定义脚本监控扩展agent">2、自定义脚本监控扩展Agent</h3>
<p>Zabbix Server与Agent之间监控数据的采集主要是通过Zabbix Server主动向Agent询问某个Key的值，Agent会根据Key去调用相应的函数去获取这个值并返回给Server端。Zabbix 2.4.7的Agent本并没有内置MySQL的监控功能（但是Server端提供了相应的Template配置），所以我们需要使用Zabbix的User Parameters功能，为MySQL添加监控脚本。</p>
<h3 id="3授权mysql登录用户agent端">3、授权mysql登录用户（agent端）</h3>
<pre><code>mysql&gt; grant usage on *.* to zabbix@127.0.0.1 identified by '123456';

mysql&gt; flush privileges;
</code></pre><h3 id="4agent端配置">4、agent端配置</h3>
<h4 id="存活检测">存活检测</h4>
<p>利用UserParameter参数自定义Agent Key。
对于需求一 ，我们采用mysqladmin这个工具来实现，命令如下：</p>
<pre><code># mysqladmin -h 127.0.0.1 -u zabbix -p123456 ping 
mysqld is alive


</code></pre><p>如果MySQL状态正常，会显示mysqld is alive，否则会提示连接不上。对于服务器端，mysqld is alive这样的句子不好理解，服务器端最好只接收1和0，1表示服务可用，0表示服务不可用。那么再改进一下这个命令，如下：</p>
<pre><code># mysqladmin -h 127.0.0.1 -u zabbix -p123456 ping |grep -c alive
1

</code></pre><p>用户名和密码放在命令中对于以后的维护不好，所以我们在/var/lib/zabbix/下创建一个包含MySQL用户名和密码的配置文件“.my.cnf”，如下：</p>
<pre><code>user=zabbix
host=127.0.0.1
password='123456'

</code></pre><p>有了这个文件后的命令变更为</p>
<pre><code>HOME=/var/lib/zabbix/ mysqladmin ping |grep -c alive
1
	
</code></pre><p>做完这一步后需要做的就是，将这个监控命令添加到Zabbix Agent中，并与一个Key对应，这样Zabbox Server就能通过这个Key获取MySQL的状态了。我们使用mysql.ping作为MySQL状态的Key。</p>
<p>首先在去除/etc/zabbix/zabbix_agentd.conf中</p>
<p>“Include=/etc/zabbix_agentd.d/” 这一行的注释符。</p>
<p>其次，在/etc/zabbix/zabbix_agentd.d/目录下创建userparameter_mysql.conf文件。在文件中添加如下命令：</p>
<pre><code>UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
</code></pre><p>使用下面的命令测试是否正常工作。</p>
<pre><code># /usr/sbin/zabbix_agentd -t mysql.ping
mysql.ping                                    [t|1]
</code></pre><h4 id="其他性能指标">其他性能指标</h4>
<h5 id="1添加userparameter_mysql">1.添加userparameter_mysql</h5>
<pre><code>vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

####监控mysql性能的脚本

UserParameter=mysql.status[*],/etc/zabbix/zabbix_agentd.d/check_mysql.sh $1

#####mysql版本

UserParameter=mysql.version,mysql -V
</code></pre><h5 id="2check_mysqlsh">2.check_mysql.sh</h5>
<pre><code>#!/bin/bash
# -------------------------------------------------------------------------------
# FileName: check_mysql.sh
# Revision: 1.0
# -------------------------------------------------------------------------------
# Copyright:
# License: GPL

# 用户名
MYSQL_USER='zabbix'

# 密码
MYSQL_PWD='zabbix@123'

# 主机地址/IP
MYSQL_HOST='ip'

# 端口
MYSQL_PORT='3306'

# 数据连接
MYSQL_CONN=&quot;/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}&quot;

# 参数是否正确
if [ $# -ne &quot;1&quot; ];then
echo &quot;arg error!&quot;
fi

# 获取数据
case $1 in
Uptime)
result=`${MYSQL_CONN} status 2&gt;/dev/null |cut -f2 -d&quot;:&quot;|cut -f1 -d&quot;T&quot;`
echo $result
;;
Com_update)
result=`${MYSQL_CONN} extended-status   2&gt;/dev/null  |grep -w &quot;Com_update&quot;|cut -d&quot;|&quot; -f3`
echo $result
;;
Slow_queries)
result=`${MYSQL_CONN} status  2&gt;/dev/null  |cut -f5 -d&quot;:&quot;|cut -f1 -d&quot;O&quot;`
echo $result
;;
Com_select)
result=`${MYSQL_CONN} extended-status  2&gt;/dev/null  |grep -w &quot;Com_select&quot;|cut -d&quot;|&quot; -f3`
echo $result
;;
Com_rollback)
result=`${MYSQL_CONN} extended-status  2&gt;/dev/null   |grep -w &quot;Com_rollback&quot;|cut -d&quot;|&quot; -f3`
echo $result
;;
Questions)
result=`${MYSQL_CONN} status   2&gt;/dev/null |cut -f4 -d&quot;:&quot;|cut -f1 -d&quot;S&quot;`
echo $result
;;
Com_insert)
result=`${MYSQL_CONN} extended-status   2&gt;/dev/null  |grep -w &quot;Com_insert&quot;|cut -d&quot;|&quot; -f3`
echo $result
;;
Com_delete)
result=`${MYSQL_CONN} extended-status   2&gt;/dev/null  |grep -w &quot;Com_delete&quot;|cut -d&quot;|&quot; -f3`
echo $result
;;
Com_commit)
result=`${MYSQL_CONN} extended-status   2&gt;/dev/null  |grep -w &quot;Com_commit&quot;|cut -d&quot;|&quot; -f3`
echo $result
;;
Bytes_sent)
result=`${MYSQL_CONN} extended-status  2&gt;/dev/null  |grep -w &quot;Bytes_sent&quot; |cut -d&quot;|&quot; -f3`
echo $result
;;
Bytes_received)
result=`${MYSQL_CONN} extended-status  2&gt;/dev/null  |grep -w &quot;Bytes_received&quot; |cut -d&quot;|&quot; -f3`
echo $result
;;
Com_begin)
result=`${MYSQL_CONN} extended-status  2&gt;/dev/null  |grep -w &quot;Com_begin&quot;|cut -d&quot;|&quot; -f3`
echo $result
;;

*)
echo &quot;Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)&quot;
;;
esac

</code></pre><h5 id="3授权">3.授权：</h5>
<pre><code>chmod +x  /etc/zabbix/zabbix_agentd.d/check_mysql.sh

Chown zabbix.zabbix  /etc/zabbix/zabbix_agentd.d/check_mysql.sh
</code></pre><h5 id="4---zabbix_agent上测试">4.   zabbix_agent上测试：</h5>
<p>zabbix_agentd -t mysql.ping</p>
<p>
        <a data-fancybox="gallery" href="/assets/image-20200408141921337.png">
            <img class="mx-auto" alt="image-20200408141921337" src="/assets/image-20200408141921337.png" />
        </a>
    </p>
<h5 id="5zabbix_server测试">5.Zabbix_server测试</h5>
<p>zabbix_get -s ip -P 端口  -k mysql.ping</p>
<p>
        <a data-fancybox="gallery" href="/assets/clip_image002.jpg">
            <img class="mx-auto" alt="img" src="/assets/clip_image002.jpg" />
        </a>
    </p>
<h3 id="5在web端进行配置">5、在web端进行配置</h3>
<p>**创建主机 **</p>
<p>
        <a data-fancybox="gallery" href="/assets/clip_image002.gif">
            <img class="mx-auto" alt="IMG_256" src="/assets/clip_image002.gif" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="/assets/clip_image004.gif">
            <img class="mx-auto" alt="IMG_257" src="/assets/clip_image004.gif" />
        </a>
    </p>
<p><strong>关联模板</strong></p>
<p>
        <a data-fancybox="gallery" href="/assets/clip_image006.gif">
            <img class="mx-auto" alt="IMG_258" src="/assets/clip_image006.gif" />
        </a>
    </p>
<p><strong>创建监控项</strong></p>
<p>
        <a data-fancybox="gallery" href="/assets/clip_image008.gif">
            <img class="mx-auto" alt="IMG_259" src="/assets/clip_image008.gif" />
        </a>
    </p>
<p><strong>创建图形</strong></p>
<p>
        <a data-fancybox="gallery" href="/assets/clip_image010.gif">
            <img class="mx-auto" alt="IMG_260" src="/assets/clip_image010.gif" />
        </a>
    </p>
<p><strong>查看监控图像</strong></p>
<p>
        <a data-fancybox="gallery" href="/assets/clip_image012.gif">
            <img class="mx-auto" alt="IMG_261" src="/assets/clip_image012.gif" />
        </a>
    </p>
<p>其他监控项以此配置完成</p>
<h3 id="6zabbix自带mysql监控项">6、zabbix自带mysql监控项</h3>
<pre><code>version:数据库版本
key_buffer_size:myisam的索引buffer大小
sort_buffer_size:会话的排序空间（每个线程会申请一个）
join_buffer_size:这是为链接操作分配的最小缓存大小，这些连接使用普通索引扫描、范围扫描、或者连接不适用索引
max_connections:最大允许同时连接的数量
max_connect_errors：允许一个主机最多的错误链接次数，如果超过了就会拒绝之后链接（默认100）。可以使用flush hosts命令去解除拒绝
open_files_limits:操作系统允许mysql打开的文件数量，可以通过opened_tables状态确定是否需要增大table_open_cache,如果opened_tables比较大且一直还在增大说明需要增大table_open_cache
max-heap_tables_size:建立的内存表的最大大小（默认16M）这个参数和tmp_table_size一起限制内部临时表的最大值(取这两个参数的小的一个），如果超过限制，则表会变为innodb或myisam引擎，（5.7.5之前是默认是myisam，5.7.6开始是innodb，可以通过internal_tmp_disk_storage_engine参数调整）。
max_allowed_packet:一个包的最大大小
##########GET INNODB INFO
#INNODB variables
innodb_version:
innodb_buffer_pool_instances：将innodb缓冲池分为指定的多个（默认为1）
innodb_buffer_pool_size:innodb缓冲池大小、5.7.5引入了innodb_buffer_pool_chunk_size,
innodb_doublewrite：是否开启doublewrite（默认开启）
innodb_read_io_threads:IO读线程的数量
innodb_write_io_threads:IO写线程的数量
########innodb status
innodb_buffer_pool_pages_total:innodb缓冲池页的数量、大小等于innodb_buffer_pool_size/(16*1024)
innodb_buffer_pool_pages_data:innodb缓冲池中包含数据的页的数量
########## GET MYSQL HITRATE
1、查询缓存命中率
如果Qcache_hits+Com_select&lt;&gt;0则为 Qcache_hits/（Qcache_hits+Com_select），否则为0

2、线程缓存命中率
如果Connections&lt;&gt;0,则为1-Threads_created/Connections，否则为0

3、myisam键缓存命中率
如果Key_read_requests&lt;&gt;0,则为1-Key_reads/Key_read_requests，否则为0

4、myisam键缓存写命中率
如果Key_write_requests&lt;&gt;0,则为1-Key_writes/Key_write_requests，否则为0

5、键块使用率
如果Key_blocks_used+Key_blocks_unused&lt;&gt;0，则Key_blocks_used/（Key_blocks_used+Key_blocks_unused），否则为0

6、创建磁盘存储的临时表比率
如果Created_tmp_disk_tables+Created_tmp_tables&lt;&gt;0,则Created_tmp_disk_tables/（Created_tmp_disk_tables+Created_tmp_tables），否则为0

7、连接使用率
如果max_connections&lt;&gt;0，则threads_connected/max_connections，否则为0

8、打开文件比率
如果open_files_limit&lt;&gt;0，则open_files/open_files_limit，否则为0

9、表缓存使用率
如果table_open_cache&lt;&gt;0，则open_tables/table_open_cache，否则为0
</code></pre><h2 id="十一-zabbix其他常用自定义监控项">十一、 zabbix其他常用自定义监控项</h2>
<h3 id="redis相关的自定义项">redis相关的自定义项</h3>
<pre><code>vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/redis.conf
UserParameter=Redis.Status,/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 ping |grep -c PONG
UserParameter=Redis_conn[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;connected_clients&quot; | awk -F':' '{print $2}'
UserParameter=Redis_rss_mem[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;used_memory_rss&quot; | awk -F':' '{print $2}'
UserParameter=Redis_lua_mem[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;used_memory_lua&quot; | awk -F':' '{print $2}'
UserParameter=Redis_cpu_sys[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;used_cpu_sys&quot; | awk -F':' '{print $2}'
UserParameter=Redis_cpu_user[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;used_cpu_user&quot; | awk -F':' '{print $2}'
UserParameter=Redis_cpu_sys_cline[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;used_cpu_sys_children&quot; | awk -F':' '{print $2}'
UserParameter=Redis_cpu_user_cline[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;used_cpu_user_children&quot; | awk -F':' '{print $2}'
UserParameter=Redis_keys_num[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w &quot;$$1&quot; | grep -w &quot;keys&quot; | grep db$3 | awk -F'=' '{print $2}' | awk -F',' '{print $1}'
UserParameter=Redis_loading[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep loading | awk -F':' '{print $$2}'

Redis.Status --检测Redis运行状态， 返回整数
Redis_conn  --检测Redis成功连接数，返回整数
Redis_rss_mem  --检测Redis系统分配内存，返回整数
Redis_lua_mem  --检测Redis引擎消耗内存，返回整数
Redis_cpu_sys --检测Redis主程序核心CPU消耗率，返回整数
Redis_cpu_user --检测Redis主程序用户CPU消耗率，返回整数
Redis_cpu_sys_cline --检测Redis后台核心CPU消耗率，返回整数
Redis_cpu_user_cline --检测Redis后台用户CPU消耗率，返回整数
Redis_keys_num --检测库键值数，返回整数
Redis_loding --检测Redis持久化文件状态，返回整数
</code></pre><h3 id="nginx相关的自定义项">nginx相关的自定义项</h3>
<pre><code>vim /etc/nginx/conf.d/default.conf
    location /nginx-status
    {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }

    
vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf
UserParameter=Nginx.active,/usr/bin/curl -s &quot;http://127.0.0.1:80/nginx-status&quot; | awk '/Active/ {print $NF}'
UserParameter=Nginx.read,/usr/bin/curl -s &quot;http://127.0.0.1:80/nginx-status&quot; | grep 'Reading' | cut -d&quot; &quot; -f2
UserParameter=Nginx.wrie,/usr/bin/curl -s &quot;http://127.0.0.1:80/nginx-status&quot; | grep 'Writing' | cut -d&quot; &quot; -f4
UserParameter=Nginx.wait,/usr/bin/curl -s &quot;http://127.0.0.1:80/nginx-status&quot; | grep 'Waiting' | cut -d&quot; &quot; -f6
UserParameter=Nginx.accepted,/usr/bin/curl -s &quot;http://127.0.0.1:80/nginx-status&quot; | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $1}'
UserParameter=Nginx.handled,/usr/bin/curl -s &quot;http://127.0.0.1:80/nginx-status&quot; | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $2}'
UserParameter=Nginx.requests,/usr/bin/curl -s &quot;http://127.0.0.1:80/nginx-status&quot; | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $3}'
</code></pre><h3 id="tcp相关的自定义项">TCP相关的自定义项</h3>
<pre><code>vim /usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh
#!/bin/bash
function ESTAB { 
/usr/sbin/ss -ant |awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'ESTAB' | awk '{print $2}'
}
function TIMEWAIT {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'TIME-WAIT' | awk '{print $2}'
}
function LISTEN {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'LISTEN' | awk '{print $2}'
}
$1

vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/cattcp.conf
UserParameter=tcp[*],/usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh $1

tcp[TIMEWAIT] --检测TCP的驻留数，返回整数
tcp[ESTAB]  --检测tcp的连接数、返回整数
tcp[LISTEN] --检测TCP的监听数，返回整数
</code></pre><h3 id="系统监控常用自带监控项">系统监控常用自带监控项</h3>
<pre><code>agent.ping 检测客户端可达性、返回nothing表示不可达。1表示可达
system.cpu.load --检测cpu负载。返回浮点数
system.cpu.util -- 检测cpu使用率。返回浮点数
vfs.dev.read -- 检测硬盘读取数据，返回是sps.ops.bps浮点类型，需要定义1024倍
vfs.dev.write -- 检测硬盘写入数据。返回是sps.ops.bps浮点类型，需要定义1024倍
net.if.out[br0] --检测网卡流速、流出方向，时间间隔为60S
net-if-in[br0] --检测网卡流速，流入方向（单位：字节） 时间间隔60S
proc.num[]  目前系统中的进程总数，时间间隔60s
proc.num[,,run] 目前正在运行的进程总数，时间间隔60S
###处理器信息
通过zabbix_get 获取负载值
合理的控制用户态、系统态、IO等待时间剋保证进程高效率的运行
系统态运行时间较高说明进程进行系统调用的次数比较多，一般的程序如果系统态运行时间占用过高就需要优化程序，减少系统调用
io等待时间过高则表明硬盘的io性能差，如果是读写文件比较频繁、读写效率要求比较高，可以考虑更换硬盘，或者使用多磁盘做raid的方案
system.cpu.swtiches --cpu的进程上下文切换，单位sps，表示每秒采样次数，api中参数history需指定为3
system.cpu.intr  --cpu中断数量、api中参数history需指定为3
system.cpu.load[percpu,avg1]  --cpu每分钟的负载值，按照核数做平均值(Processor load (1 min average per core))，api中参数history需指定为0
system.cpu.load[percpu,avg5]  --cpu每5分钟的负载值，按照核数做平均值(Processor load (5 min average per core))，api中参数history需指定为0
system.cpu.load[percpu,avg15]  --cpu每5分钟的负载值，按照核数做平均值(Processor load (15 min average per core))，api中参数history需指定为0
</code></pre><h3 id="系统监控常用自定义监控项">系统监控常用自定义监控项</h3>
<pre><code>####内存相关
vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/catcarm.conf
UserParameter=ram.info[*],/bin/cat  /proc/meminfo  |awk '/^$1:{print $2}'
ram.info[Cached] --检测内存的缓存使用量、返回整数，需要定义1024倍
ram.info[MemFree] --检测内存的空余量，返回整数，需要定义1024倍
ram.info[Buffers] --检测内存的使用量，返回整数，需要定义1024倍

####TCP相关的自定义项
vim /usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh
#!/bin/bash
function ESTAB { 
/usr/sbin/ss -ant |awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'ESTAB' | awk '{print $2}'
}
function TIMEWAIT {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'TIME-WAIT' | awk '{print $2}'
}
function LISTEN {
/usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'LISTEN' | awk '{print $2}'
}
$1

vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/cattcp.conf
UserParameter=tcp[*],/usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh $1

tcp[TIMEWAIT] --检测TCP的驻留数，返回整数
tcp[ESTAB]  --检测tcp的连接数、返回整数
tcp[LISTEN] --检测TCP的监听数，返回整数
</code></pre>
        </div>

        


        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/post/Linux-%E8%BF%90%E7%BB%B4%E7%AC%94%E8%AE%B0/Zabbix/%E7%9B%91%E6%8E%A7%E4%B8%AD%E5%BF%83Zabbix%E5%85%A5%E9%97%A8/">监控中心Zabbix入门 </a></li>
        
        <li><a href="/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/">Linux 基础配置 </a></li>
        
        <li><a href="/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/linux-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4-/">Linux 常用命令 </a></li>
        
        <li><a href="/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/Linux%E6%96%87%E4%BB%B6%E7%89%B9%E6%AE%8A%E6%9D%83%E9%99%90SUIDSGID%E4%B8%8ESBIT/">Linux文件特殊权限 </a></li>
        
        <li><a href="/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/Linux-%E7%A3%81%E7%9B%98%E6%8C%82%E8%BD%BD/">Liunx 磁盘分区与文件挂载 </a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='/tags/Zabbix'>Zabbix</a></li>
                
            </ul>
            
        </div>
    </article>
    
    

    
    
</div>

                    <footer id="footer">
    <div>
        &copy; 2021 <a href="https://gitmatrix.gitee.io/">matrix By matrix</a>
        
    </div>
    <br />
    
    <div>
        <div class="github-badge">
            <a href="https://gohugo.io/" target="_black" rel="nofollow"><span class="badge-subject">Powered by</span><span class="badge-value bg-blue">Hugo</span></a>
        </div>
        
        <div class="github-badge">
            <a href="https://github.com/flysnow-org/maupassant-hugo" target="_black"><span class="badge-subject">Theme</span><span class="badge-value bg-yellowgreen">Maupassant</span></a>
        </div>
    </div>
</footer>


    
    <script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script><script src="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/js/totop.js?v=0.0.0' async=""></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/js/douban.js'></script>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://gitmatrix.gitee.io/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://gitmatrix.gitee.io/">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/" title="Linux 基础配置 ">Linux 基础配置 </a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/linux-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4-/" title="Linux 常用命令 ">Linux 常用命令 </a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/Linux%E6%96%87%E4%BB%B6%E7%89%B9%E6%AE%8A%E6%9D%83%E9%99%90SUIDSGID%E4%B8%8ESBIT/" title="Linux文件特殊权限 ">Linux文件特殊权限 </a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/Linux-%E7%A3%81%E7%9B%98%E6%8C%82%E8%BD%BD/" title="Liunx 磁盘分区与文件挂载 ">Liunx 磁盘分区与文件挂载 </a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Mysql-%E6%95%B0%E6%8D%AE%E5%BA%93/my.cnf-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3/" title="my.cnf 配置文件详解">my.cnf 配置文件详解</a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Mysql-%E6%95%B0%E6%8D%AE%E5%BA%93/Mysql-%E6%93%8D%E4%BD%9C/" title="Mysql 基本操作">Mysql 基本操作</a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Mysql-%E6%95%B0%E6%8D%AE%E5%BA%93/Mysql%E4%BD%93%E7%B3%BB%E7%BB%93%E6%9E%84%E7%AE%A1%E7%90%86/" title="Mysql体系结构管理">Mysql体系结构管理</a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/RAID-%E7%A3%81%E7%9B%98%E9%98%B5%E5%88%97/" title="RAID 磁盘阵列配置 ">RAID 磁盘阵列配置 </a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/Linux-%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE/rpm-%E4%B8%8E-yum-/" title="RPM 与 Yum ">RPM 与 Yum </a>
    </li>
    
    <li>
        <a href="https://gitmatrix.gitee.io/post/SSH/SSH-%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C/" title="SSH 基本操作">SSH 基本操作</a>
    </li>
    
</ul>
    </section>

    
<section class="widget">
    <h3 class="widget-title" style="color:#6E718A">课程直达</h3>
    <ul class="widget-list">
        
        <li>
            <a href="https://www.bilibili.com/video/BV1nA411h7C9" title="Burpsuite使用教程" target="_blank" style="color:#6E718A">
                
                    <img src="https://gitee.com/gitmatrix/images/raw/master/img/20210116152721.png">
                
            </a>
        </li>
        
        <li>
            <a href="https://www.bilibili.com/video/BV1yf4y1i7Pb?p=1" title="网络安全提升技术与渗透测试原理深度解析" target="_blank" style="color:#6E718A">
                
                    <img src="https://gitee.com/gitmatrix/images/raw/master/img/6f19fe2958f4d3c5edaee825cda334bac074abc8.jpg">
                
            </a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title"><a href='/categories/'>分类</a></h3>
<ul class="widget-list">
    
    <li><a href="https://gitmatrix.gitee.io/categories/Liunx/">Liunx (6)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/Mysql/">Mysql (3)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/SSH/">SSH (4)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/Test/">Test (1)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/Web-%E5%AE%89%E5%85%A8/">Web 安全 (9)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/web%E5%9F%BA%E7%A1%80/">web基础 (1)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/%E4%BF%A1%E6%81%AF%E6%94%B6%E9%9B%86/">信息收集 (10)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/%E5%8D%81%E5%A4%A7%E6%BC%8F%E6%B4%9E/">十大漏洞 (8)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/%E6%95%99%E7%A8%8B/">教程 (1)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/%E7%BD%91%E7%BB%9C%E5%AE%89%E5%85%A8%E6%B3%95/">网络安全法 (1)</a></li>
    
    <li><a href="https://gitmatrix.gitee.io/categories/%E8%BF%90%E7%BB%B4/">运维 (2)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title"><a href='/tags/'>标签</a></h3>
<div class="tagcloud">
    
    <a href="https://gitmatrix.gitee.io/tags/CSRF/">CSRF</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Chrome-Extension/">Chrome Extension</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Chrome%E6%8F%92%E4%BB%B6/">Chrome插件</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Google-hacking/">Google hacking</a>
    
    <a href="https://gitmatrix.gitee.io/tags/JavaScript/">JavaScript</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Linux/">Linux</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Mysql/">Mysql</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Payload/">Payload</a>
    
    <a href="https://gitmatrix.gitee.io/tags/XSS/">XSS</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Zabbix/">Zabbix</a>
    
    <a href="https://gitmatrix.gitee.io/tags/js/">js</a>
    
    <a href="https://gitmatrix.gitee.io/tags/Mysql/">Mysql</a>
    
    <a href="https://gitmatrix.gitee.io/tags/sql/">sql</a>
    
    <a href="https://gitmatrix.gitee.io/tags/ssh/">ssh</a>
    
    <a href="https://gitmatrix.gitee.io/tags/test/">test</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD%E7%BD%91%E7%BB%9C%E5%AE%89%E5%85%A8%E6%B3%95/">中华人民共和国网络安全法</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E5%9F%BA%E6%9C%AC%E4%BF%A1%E6%81%AF%E6%94%B6%E9%9B%86/">基本信息收集</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%8C%87%E7%BA%B9%E8%AF%86%E5%88%AB/">指纹识别</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%94%B6%E9%9B%86%E5%AD%90%E5%9F%9F%E4%BF%A1%E6%81%AF/">收集子域信息</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%94%B6%E9%9B%86%E6%95%8F%E6%84%9F%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6/">收集敏感目录文件</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%94%BB%E5%87%BB/">攻击</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%95%99%E7%A8%8B/">教程</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%95%B4%E7%AB%99%E5%88%86%E6%9E%90/">整站分析</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%96%87%E4%BB%B6/">文件</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%B8%97%E9%80%8F%E6%B5%8B%E8%AF%95%E4%BB%8B%E7%BB%8D/">渗透测试介绍</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%B8%97%E9%80%8F%E6%B5%8B%E8%AF%95%E6%B5%81%E7%A8%8B/">渗透测试流程</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E6%BC%8F%E6%B4%9E/">漏洞</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E7%9C%9F%E5%AE%9EIP%E5%9C%B0%E5%9D%80%E6%9F%A5%E8%AF%A2/">真实IP地址查询</a>
    
    <a href="https://gitmatrix.gitee.io/tags/%E9%9D%B6%E5%9C%BA/">靶场</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://www.bugbank.cn/" title="漏洞银行">漏洞银行</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.xf1433.com/59.html" title="电脑黑客书籍在线阅读">电脑黑客书籍在线阅读</a>
        </li>
        
        <li>
            <a target="_blank" href="http://yuedu.baidu.com/ebook/14a722970740be1e640e9a3e" title="Android Gradle权威指南">Android Gradle权威指南</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://gitmatrix.gitee.io/index.xml"></a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
</body>

</html>